def validate_item_tax_template(self): for item in self.doc.get('items'): if item.item_code and item.get('item_tax_template'): item_doc = frappe.get_cached_doc("Item", item.item_code) args = { 'tax_category': self.doc.get('tax_category'), 'posting_date': self.doc.get('posting_date'), 'bill_date': self.doc.get('bill_date'), 'transaction_date': self.doc.get('transaction_date') } item_group = item_doc.item_group item_group_taxes = [] while item_group: item_group_doc = frappe.get_cached_doc( 'Item Group', item_group) item_group_taxes += item_group_doc.taxes or [] item_group = item_group_doc.parent_item_group item_taxes = item_doc.taxes or [] if not item_group_taxes and (not item_taxes): # No validation if no taxes in item or item group continue taxes = _get_item_tax_template(args, item_taxes + item_group_taxes, for_validate=True) if item.item_tax_template not in taxes: frappe.throw( _("Row {0}: Invalid Item Tax Template for item {1}"). format(item.idx, frappe.bold(item.item_code)))
def get_tax_template(doctype, txt, searchfield, start, page_len, filters): item_doc = frappe.get_cached_doc('Item', filters.get('item_code')) item_group = filters.get('item_group') taxes = item_doc.taxes or [] while item_group: item_group_doc = frappe.get_cached_doc('Item Group', item_group) taxes += item_group_doc.taxes or [] item_group = item_group_doc.parent_item_group if not taxes: fields = get_fields("Item Tax Template", ["name"]) return frappe.db.sql( """ SELECT %(fields)s FROM `tabItem Tax Template` """, {fields: ", ".join(fields)}) else: args = { 'item_code': filters.get('item_code'), 'posting_date': filters.get('valid_from'), 'tax_category': filters.get('tax_category') } taxes = _get_item_tax_template(args, taxes, for_validate=True) return [(d, ) for d in set(taxes)]
def validate_item_tax_template(self): for item in self.doc.get('items'): if item.item_code and item.get('item_tax_template'): item_doc = frappe.get_cached_doc("Item", item.item_code) args = { 'net_rate': item.net_rate or item.rate, 'tax_category': self.doc.get('tax_category'), 'posting_date': self.doc.get('posting_date'), 'bill_date': self.doc.get('bill_date'), 'transaction_date': self.doc.get('transaction_date'), 'company': self.doc.get('company') } item_group = item_doc.item_group item_group_taxes = [] while item_group: item_group_doc = frappe.get_cached_doc('Item Group', item_group) item_group_taxes += item_group_doc.taxes or [] item_group = item_group_doc.parent_item_group item_taxes = item_doc.taxes or [] if not item_group_taxes and (not item_taxes): # No validation if no taxes in item or item group continue taxes = _get_item_tax_template(args, item_taxes + item_group_taxes, for_validate=True) if taxes: if item.item_tax_template not in taxes: item.item_tax_template = taxes[0] frappe.msgprint(_("Row {0}: Item Tax template updated as per validity and rate applied").format( item.idx, frappe.bold(item.item_code) ))
def get_tax_template(doctype, txt, searchfield, start, page_len, filters): item_doc = frappe.get_cached_doc('Item', filters.get('item_code')) item_group = filters.get('item_group') taxes = item_doc.taxes or [] while item_group: item_group_doc = frappe.get_cached_doc('Item Group', item_group) taxes += item_group_doc.taxes or [] item_group = item_group_doc.parent_item_group if not taxes: return frappe.db.sql(""" SELECT name FROM `tabItem Tax Template` """) else: valid_from = filters.get('valid_from') valid_from = valid_from[1] if isinstance(valid_from, list) else valid_from args = { 'item_code': filters.get('item_code'), 'posting_date': valid_from, 'tax_category': filters.get('tax_category'), 'company': filters.get('company') } taxes = _get_item_tax_template(args, taxes, for_validate=True) return [(d, ) for d in set(taxes)]
def get_tax_template(doctype, txt, searchfield, start, page_len, filters): item_doc = frappe.get_cached_doc("Item", filters.get("item_code")) item_group = filters.get("item_group") company = filters.get("company") taxes = item_doc.taxes or [] while item_group: item_group_doc = frappe.get_cached_doc("Item Group", item_group) taxes += item_group_doc.taxes or [] item_group = item_group_doc.parent_item_group if not taxes: return frappe.get_all("Item Tax Template", filters={ "disabled": 0, "company": company }, as_list=True) else: valid_from = filters.get("valid_from") valid_from = valid_from[1] if isinstance(valid_from, list) else valid_from args = { "item_code": filters.get("item_code"), "posting_date": valid_from, "tax_category": filters.get("tax_category"), "company": company, } taxes = _get_item_tax_template(args, taxes, for_validate=True) return [(d, ) for d in set(taxes)]