perf(minor): improve sales invoice submission (#27916)
* perf: skip get_pricing_rules if no pricing rule exists * perf: fetch mode of payments data in single query * perf: get total company stock only for purchase order * perf: skip insertion of stock ledger entry * fix: undo changes to allow negative stock flag * fix: sider Co-authored-by: Ankush Menat <ankushmenat@gmail.com> Co-authored-by: Ankush Menat <ankush@iwebnotes.com>
This commit is contained in:
commit
879a1fca76
@ -29,6 +29,9 @@ def get_pricing_rules(args, doc=None):
|
|||||||
pricing_rules = []
|
pricing_rules = []
|
||||||
values = {}
|
values = {}
|
||||||
|
|
||||||
|
if not frappe.db.exists('Pricing Rule', {'disable': 0, args.transaction_type: 1}):
|
||||||
|
return
|
||||||
|
|
||||||
for apply_on in ['Item Code', 'Item Group', 'Brand']:
|
for apply_on in ['Item Code', 'Item Group', 'Brand']:
|
||||||
pricing_rules.extend(_get_pricing_rules(apply_on, args, values))
|
pricing_rules.extend(_get_pricing_rules(apply_on, args, values))
|
||||||
if pricing_rules and not apply_multiple_pricing_rules(pricing_rules):
|
if pricing_rules and not apply_multiple_pricing_rules(pricing_rules):
|
||||||
|
|||||||
@ -1975,22 +1975,23 @@ def update_multi_mode_option(doc, pos_profile):
|
|||||||
def append_payment(payment_mode):
|
def append_payment(payment_mode):
|
||||||
payment = doc.append('payments', {})
|
payment = doc.append('payments', {})
|
||||||
payment.default = payment_mode.default
|
payment.default = payment_mode.default
|
||||||
payment.mode_of_payment = payment_mode.parent
|
payment.mode_of_payment = payment_mode.mop
|
||||||
payment.account = payment_mode.default_account
|
payment.account = payment_mode.default_account
|
||||||
payment.type = payment_mode.type
|
payment.type = payment_mode.type
|
||||||
|
|
||||||
doc.set('payments', [])
|
doc.set('payments', [])
|
||||||
invalid_modes = []
|
invalid_modes = []
|
||||||
for pos_payment_method in pos_profile.get('payments'):
|
mode_of_payments = [d.mode_of_payment for d in pos_profile.get('payments')]
|
||||||
pos_payment_method = pos_payment_method.as_dict()
|
mode_of_payments_info = get_mode_of_payments_info(mode_of_payments, doc.company)
|
||||||
|
|
||||||
payment_mode = get_mode_of_payment_info(pos_payment_method.mode_of_payment, doc.company)
|
for row in pos_profile.get('payments'):
|
||||||
|
payment_mode = mode_of_payments_info.get(row.mode_of_payment)
|
||||||
if not payment_mode:
|
if not payment_mode:
|
||||||
invalid_modes.append(get_link_to_form("Mode of Payment", pos_payment_method.mode_of_payment))
|
invalid_modes.append(get_link_to_form("Mode of Payment", row.mode_of_payment))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
payment_mode[0].default = pos_payment_method.default
|
payment_mode.default = row.default
|
||||||
append_payment(payment_mode[0])
|
append_payment(payment_mode)
|
||||||
|
|
||||||
if invalid_modes:
|
if invalid_modes:
|
||||||
if invalid_modes == 1:
|
if invalid_modes == 1:
|
||||||
@ -2006,6 +2007,24 @@ def get_all_mode_of_payments(doc):
|
|||||||
where mpa.parent = mp.name and mpa.company = %(company)s and mp.enabled = 1""",
|
where mpa.parent = mp.name and mpa.company = %(company)s and mp.enabled = 1""",
|
||||||
{'company': doc.company}, as_dict=1)
|
{'company': doc.company}, as_dict=1)
|
||||||
|
|
||||||
|
def get_mode_of_payments_info(mode_of_payments, company):
|
||||||
|
data = frappe.db.sql(
|
||||||
|
"""
|
||||||
|
select
|
||||||
|
mpa.default_account, mpa.parent as mop, mp.type as type
|
||||||
|
from
|
||||||
|
`tabMode of Payment Account` mpa,`tabMode of Payment` mp
|
||||||
|
where
|
||||||
|
mpa.parent = mp.name and
|
||||||
|
mpa.company = %s and
|
||||||
|
mp.enabled = 1 and
|
||||||
|
mp.name in (%s)
|
||||||
|
group by
|
||||||
|
mp.name
|
||||||
|
""", (company, mode_of_payments), as_dict=1)
|
||||||
|
|
||||||
|
return {row.get('mop'): row for row in data}
|
||||||
|
|
||||||
def get_mode_of_payment_info(mode_of_payment, company):
|
def get_mode_of_payment_info(mode_of_payment, company):
|
||||||
return frappe.db.sql("""
|
return frappe.db.sql("""
|
||||||
select mpa.default_account, mpa.parent, mp.type as type
|
select mpa.default_account, mpa.parent, mp.type as type
|
||||||
|
|||||||
@ -89,7 +89,13 @@ def get_item_details(args, doc=None, for_validate=False, overwrite_warehouse=Tru
|
|||||||
out.update(get_bin_details(args.item_code, args.get("from_warehouse")))
|
out.update(get_bin_details(args.item_code, args.get("from_warehouse")))
|
||||||
|
|
||||||
elif out.get("warehouse"):
|
elif out.get("warehouse"):
|
||||||
out.update(get_bin_details(args.item_code, out.warehouse, args.company))
|
if doc and doc.get('doctype') == 'Purchase Order':
|
||||||
|
# calculate company_total_stock only for po
|
||||||
|
bin_details = get_bin_details(args.item_code, out.warehouse, args.company)
|
||||||
|
else:
|
||||||
|
bin_details = get_bin_details(args.item_code, out.warehouse)
|
||||||
|
|
||||||
|
out.update(bin_details)
|
||||||
|
|
||||||
# update args with out, if key or value not exists
|
# update args with out, if key or value not exists
|
||||||
for key, value in iteritems(out):
|
for key, value in iteritems(out):
|
||||||
@ -485,7 +491,8 @@ def get_item_tax_template(args, item, out):
|
|||||||
"item_tax_template": None
|
"item_tax_template": None
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
item_tax_template = args.get("item_tax_template")
|
item_tax_template = None
|
||||||
|
if item.taxes:
|
||||||
item_tax_template = _get_item_tax_template(args, item.taxes, out)
|
item_tax_template = _get_item_tax_template(args, item.taxes, out)
|
||||||
|
|
||||||
if not item_tax_template:
|
if not item_tax_template:
|
||||||
@ -502,8 +509,9 @@ def _get_item_tax_template(args, taxes, out=None, for_validate=False):
|
|||||||
taxes_with_no_validity = []
|
taxes_with_no_validity = []
|
||||||
|
|
||||||
for tax in taxes:
|
for tax in taxes:
|
||||||
tax_company = frappe.get_value("Item Tax Template", tax.item_tax_template, 'company')
|
tax_company = frappe.get_cached_value("Item Tax Template", tax.item_tax_template, 'company')
|
||||||
if (tax.valid_from or tax.maximum_net_rate) and tax_company == args['company']:
|
if tax_company == args['company']:
|
||||||
|
if (tax.valid_from or tax.maximum_net_rate):
|
||||||
# In purchase Invoice first preference will be given to supplier invoice date
|
# In purchase Invoice first preference will be given to supplier invoice date
|
||||||
# if supplier date is not present then posting date
|
# if supplier date is not present then posting date
|
||||||
validation_date = args.get('transaction_date') or args.get('bill_date') or args.get('posting_date')
|
validation_date = args.get('transaction_date') or args.get('bill_date') or args.get('posting_date')
|
||||||
@ -512,7 +520,6 @@ def _get_item_tax_template(args, taxes, out=None, for_validate=False):
|
|||||||
and is_within_valid_range(args, tax):
|
and is_within_valid_range(args, tax):
|
||||||
taxes_with_validity.append(tax)
|
taxes_with_validity.append(tax)
|
||||||
else:
|
else:
|
||||||
if tax_company == args['company']:
|
|
||||||
taxes_with_no_validity.append(tax)
|
taxes_with_no_validity.append(tax)
|
||||||
|
|
||||||
if taxes_with_validity:
|
if taxes_with_validity:
|
||||||
@ -890,8 +897,7 @@ def get_pos_profile_item_details(company, args, pos_profile=None, update_data=Fa
|
|||||||
res[fieldname] = pos_profile.get(fieldname)
|
res[fieldname] = pos_profile.get(fieldname)
|
||||||
|
|
||||||
if res.get("warehouse"):
|
if res.get("warehouse"):
|
||||||
res.actual_qty = get_bin_details(args.item_code,
|
res.actual_qty = get_bin_details(args.item_code, res.warehouse).get("actual_qty")
|
||||||
res.warehouse).get("actual_qty")
|
|
||||||
|
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
|||||||
@ -123,12 +123,11 @@ def set_as_cancel(voucher_type, voucher_no):
|
|||||||
(now(), frappe.session.user, voucher_type, voucher_no))
|
(now(), frappe.session.user, voucher_type, voucher_no))
|
||||||
|
|
||||||
def make_entry(args, allow_negative_stock=False, via_landed_cost_voucher=False):
|
def make_entry(args, allow_negative_stock=False, via_landed_cost_voucher=False):
|
||||||
args.update({"doctype": "Stock Ledger Entry"})
|
args["doctype"] = "Stock Ledger Entry"
|
||||||
sle = frappe.get_doc(args)
|
sle = frappe.get_doc(args)
|
||||||
sle.flags.ignore_permissions = 1
|
sle.flags.ignore_permissions = 1
|
||||||
sle.allow_negative_stock=allow_negative_stock
|
sle.allow_negative_stock=allow_negative_stock
|
||||||
sle.via_landed_cost_voucher = via_landed_cost_voucher
|
sle.via_landed_cost_voucher = via_landed_cost_voucher
|
||||||
sle.insert()
|
|
||||||
sle.submit()
|
sle.submit()
|
||||||
return sle
|
return sle
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user