コード例 #1
0
def get_open_count(doctype, name, dashboard_data=None):
    '''Get open count for given transactions and filters

    :param doctype: Reference DocType
    :param name: Reference Name
    :param transactions: List of transactions (json/dict)
    :param filters: optional filters (json/list)'''

    if not dashboard_data:
        from frappe.desk.notifications import get_open_count
        return get_open_count(doctype, name)

    frappe.has_permission(doc=frappe.get_doc(doctype, name), throw=True)

    meta = frappe.get_meta(doctype)
    if not dashboard_data:
        links = meta.get_dashboard_data()
    else:
        links = frappe._dict(json.loads(dashboard_data))

    # compile all items in a list
    items = []
    for group in links.transactions:
        items.extend(group.get('items'))

    out = []
    for d in items:
        if d in links.get('internal_links', {}):
            # internal link
            continue

        filters = get_filters_for(d)
        fieldname = links.get('non_standard_fieldnames', {}).get(d, links.fieldname)
        data = {'name': d}
        if filters:
            # get the fieldname for the current document
            # we only need open documents related to the current document
            filters[fieldname] = name
            total = len(frappe.get_all(d, fields='name',
                filters=filters, limit=100, distinct=True, ignore_ifnull=True))
            data['open_count'] = total

        total = len(frappe.get_all(d, fields='name',
            filters={fieldname: name}, limit=100, distinct=True, ignore_ifnull=True))
        data['count'] = total
        out.append(data)

    out = {
        'count': out,
    }

    module = frappe.get_meta_module(doctype)
    if hasattr(module, 'get_timeline_data'):
        out['timeline_data'] = module.get_timeline_data(doctype, name)

    return out
コード例 #2
0
ファイル: party_status.py プロジェクト: venetanji/erpnext
def get_party_status(doc):
	'''return party status based on open documents'''
	status = default_status[doc.doctype]
	for doctype in status_depends_on[doc.doctype]:
		filters = get_filters_for(doctype)
		filters[doc.doctype.lower()] = doc.name
		if filters:
			open_count = frappe.get_all(doctype, fields='name', filters=filters, limit_page_length=1)
			if len(open_count) > 0:
				status = 'Open'
				break

	return status
コード例 #3
0
def get_party_status(doc):
	'''return party status based on open documents'''
	status = default_status[doc.doctype]
	for doctype in status_depends_on[doc.doctype]:
		filters = get_filters_for(doctype)
		filters[doc.doctype.lower()] = doc.name
		if filters:
			open_count = frappe.get_all(doctype, fields='name', filters=filters, limit_page_length=1)
			if len(open_count) > 0:
				status = 'Open'
				break

	return status
コード例 #4
0
def execute():
	for party_type in ('Customer', 'Supplier'):
		frappe.reload_doctype(party_type)

		# set all as default status
		frappe.db.sql('update `tab{0}` set status=%s'.format(party_type), default_status[party_type])

		for doctype in status_depends_on[party_type]:
			filters = get_filters_for(doctype)
			parties = frappe.get_all(doctype, fields="{0} as party".format(party_type.lower()),
				filters=filters, limit_page_length=1)

			parties = filter(None, [p.party for p in parties])

			if parties:
				frappe.db.sql('update `tab{0}` set status="Open" where name in ({1})'.format(party_type,
					', '.join(len(parties) * ['%s'])), parties)
コード例 #5
0
def notify_status(doc, method=None):
	'''Notify status to customer, supplier'''

	party_type = None
	for key, doctypes in status_depends_on.iteritems():
		if doc.doctype in doctypes:
			party_type = key
			break

	if not party_type:
		return

	name = doc.get(party_type.lower())
	if not name:
		return

	party = frappe.get_doc(party_type, name)
	filters = get_filters_for(doc.doctype)
	party.flags.ignore_mandatory = True

	status = None
	if filters:
		if evaluate_filters(doc, filters):
			# filters match, passed document is open
			status = 'Open'

	if status=='Open':
		if party.status != 'Open':
			# party not open, make it open
			party.status = 'Open'
			party.save(ignore_permissions=True)

	else:
		if party.status == 'Open':
			# may be open elsewhere, check
			# default status
			party.status = status
			update_status(party)

	party.update_modified()
	party.notify_update()
コード例 #6
0
def execute():
    for party_type in ('Customer', 'Supplier'):
        frappe.reload_doctype(party_type)

        # set all as default status
        frappe.db.sql('update `tab{0}` set status=%s'.format(party_type),
                      default_status[party_type])

        for doctype in status_depends_on[party_type]:
            filters = get_filters_for(doctype)
            parties = frappe.get_all(doctype,
                                     fields="{0} as party".format(
                                         party_type.lower()),
                                     filters=filters,
                                     limit_page_length=1)

            parties = filter(None, [p.party for p in parties])

            if parties:
                frappe.db.sql(
                    'update `tab{0}` set status="Open" where name in ({1})'.
                    format(party_type,
                           ', '.join(len(parties) * ['%s'])), parties)
コード例 #7
0
ファイル: api.py プロジェクト: finbyz/chemical-v-12
def get_open_count(doctype, name, links):
	'''Get open count for given transactions and filters

	:param doctype: Reference DocType
	:param name: Reference Name
	:param transactions: List of transactions (json/dict)
	:param filters: optional filters (json/list)'''

	frappe.has_permission(doc=frappe.get_doc(doctype, name), throw=True)

	meta = frappe.get_meta(doctype)
	#links = meta.get_dashboard_data()

	links = frappe._dict({
		'fieldname': 'party',
		'transactions': [
			{
				'label': _('Outward Sample'),
				'items': ['Outward Sample']
			},
			{
				'label': _('Inward Sample'),
				'items': ['Inward Sample']
			},
		]
	})
    #frappe.msgprint(str(links))
    #links = frappe._dict(links)
    #return {'count':0}


	# compile all items in a list
	items = []
	for group in links.transactions:
		items.extend(group.get('items'))

	out = []
	for d in items:
		if d in links.get('internal_links', {}):
			# internal link
			continue

		filters = get_filters_for(d)
		fieldname = links.get('non_standard_fieldnames', {}).get(d, links.fieldname)
        #return fieldname
		data = {'name': d}
		if filters:
			# get the fieldname for the current document
			# we only need open documents related to the current document
			filters[fieldname] = name
			total = len(frappe.get_all(d, fields='name',
				filters=filters, limit=100, distinct=True, ignore_ifnull=True))
			data['open_count'] = total

		total = len(frappe.get_all(d, fields='name',
			filters={fieldname: name}, limit=100, distinct=True, ignore_ifnull=True))
		data['count'] = total
		out.append(data)

	out = {
		'count': out,
	}

	module = frappe.get_meta_module(doctype)
	if hasattr(module, 'get_timeline_data'):
		out['timeline_data'] = module.get_timeline_data(doctype, name)
    
	return out

	
# 	if isinstance(doc, string_types):
# 		doc = json.loads(doc)
		
# 	so_list = [d['sales_order'] for d in doc['sales_orders'] if d['sales_order']]

# 	sample_list = [d['outward_sample'] for d in doc['finish_items'] if d['outward_sample']]
# 	if not sample_list:
# 		frappe.msgprint(_("Please enter Sales Orders in the above table"))
# 		return []

# 	for sample in sample_list:
# 		sample_doc = frappe.get_doc("Outward Sample",sample)
# 		items_list = [d.item_code for d in sample_doc.details]

# 		for item_code in items_list:
# 			items = frappe.db.sql("""select item as item_code,name as bom_no from `tabBOM` where item = '%s' and is_active = 1 and is_default = 1 and docstatus= 1"""%item_code,as_dict=1)
			
	
# 	if doc['item_code']:
# 		item_condition = ' and so_item.item_code = "{0}"'.format(frappe.db.escape( doc['item_code']))

# 		packed_items = frappe.db.sql("""select distinct pi.parent, pi.item_code, pi.warehouse as warehouse,
# 			(((so_item.qty - so_item.work_order_qty) * pi.qty) / so_item.qty)
# 				as pending_qty, pi.parent_item, so_item.name
# 			from `tabSales Order Item` so_item, `tabPacked Item` pi
# 			where so_item.parent = pi.parent and so_item.docstatus = 1
# 			and pi.parent_item = so_item.item_code
# 			and so_item.parent in (%s) and so_item.qty > so_item.work_order_qty
# 			and exists (select name from `tabBOM` bom where bom.item=pi.item_code
# 					and bom.is_active = 1) %s""" % \
# 			(", ".join(["%s"] * len(so_list)), item_condition), tuple(so_list), as_dict=1)

# 	add_items(items,packed_items)
# 	# calculate_total_planned_qty()

# def add_items(self, items):
# 	self.set('po_items', [])
# 	for data in items:
# 		item_details = get_item_details(data.item_code)
# 		pi = self.append('po_items', {
# 			'include_exploded_items': 1,
# 			'warehouse': data.warehouse,
# 			'item_code': data.item_code,
# 			'description': item_details and item_details.description or '',
# 			'stock_uom': item_details and item_details.stock_uom or '',
# 			'bom_no': item_details and item_details.bom_no or '',
# 			'planned_qty': data.pending_qty,
# 			'pending_qty': data.pending_qty,
# 			'planned_start_date': now_datetime(),
# 			'product_bundle_item': data.parent_item
# 		})

# 		if self.get_items_from == "Sales Order":
# 			pi.sales_order = data.parent
# 			pi.sales_order_item = data.name

# 		elif self.get_items_from == "Material Request":
# 			pi.material_request = data.parent
# 			pi.material_request_item = data.name

# # def calculate_total_planned_qty(self):
# # 	self.total_planned_qty = 0
# # 	for d in self.po_items:
# # 		self.total_planned_qty += flt(d.planned_qty)

	
		

	
コード例 #8
0
ファイル: api.py プロジェクト: finbyz/chemical
def get_open_count(doctype, name, links):
    '''Get open count for given transactions and filters

	:param doctype: Reference DocType
	:param name: Reference Name
	:param transactions: List of transactions (json/dict)
	:param filters: optional filters (json/list)'''

    frappe.has_permission(doc=frappe.get_doc(doctype, name), throw=True)

    meta = frappe.get_meta(doctype)
    #links = meta.get_dashboard_data()

    links = frappe._dict({
        'fieldname':
        'party',
        'transactions': [
            {
                'label': _('Outward Sample'),
                'items': ['Outward Sample']
            },
            {
                'label': _('Inward Sample'),
                'items': ['Inward Sample']
            },
        ]
    })
    #frappe.msgprint(str(links))
    #links = frappe._dict(links)
    #return {'count':0}

    # compile all items in a list
    items = []
    for group in links.transactions:
        items.extend(group.get('items'))

    out = []
    for d in items:
        if d in links.get('internal_links', {}):
            # internal link
            continue

        filters = get_filters_for(d)
        fieldname = links.get('non_standard_fieldnames',
                              {}).get(d, links.fieldname)
        #return fieldname
        data = {'name': d}
        if filters:
            # get the fieldname for the current document
            # we only need open documents related to the current document
            filters[fieldname] = name
            total = len(
                frappe.get_all(d,
                               fields='name',
                               filters=filters,
                               limit=100,
                               distinct=True,
                               ignore_ifnull=True))
            data['open_count'] = total

        total = len(
            frappe.get_all(d,
                           fields='name',
                           filters={fieldname: name},
                           limit=100,
                           distinct=True,
                           ignore_ifnull=True))
        data['count'] = total
        out.append(data)

    out = {
        'count': out,
    }

    module = frappe.get_meta_module(doctype)
    if hasattr(module, 'get_timeline_data'):
        out['timeline_data'] = module.get_timeline_data(doctype, name)

    return out