Skip to content

Commit

Permalink
Merge branch 'develop' into product_bundle_clientside
Browse files Browse the repository at this point in the history
  • Loading branch information
ankush committed Jun 27, 2022
2 parents 54e3eb0 + 173588e commit 035ef03
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion erpnext/selling/doctype/quotation/quotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,15 @@ def make_sales_order(source_name, target_doc=None):

def _make_sales_order(source_name, target_doc=None, ignore_permissions=False):
customer = _make_customer(source_name, ignore_permissions)
ordered_items = frappe._dict(
frappe.db.get_all(
"Sales Order Item",
{"prevdoc_docname": source_name, "docstatus": 1},
["item_code", "sum(qty)"],
group_by="item_code",
as_list=1,
)
)

def set_missing_values(source, target):
if customer:
Expand All @@ -222,7 +231,9 @@ def set_missing_values(source, target):
target.run_method("calculate_taxes_and_totals")

def update_item(obj, target, source_parent):
target.stock_qty = flt(obj.qty) * flt(obj.conversion_factor)
balance_qty = obj.qty - ordered_items.get(obj.item_code, 0.0)
target.qty = balance_qty if balance_qty > 0 else 0
target.stock_qty = flt(target.qty) * flt(obj.conversion_factor)

if obj.against_blanket_order:
target.against_blanket_order = obj.against_blanket_order
Expand All @@ -238,6 +249,7 @@ def update_item(obj, target, source_parent):
"doctype": "Sales Order Item",
"field_map": {"parent": "prevdoc_docname"},
"postprocess": update_item,
"condition": lambda doc: doc.qty > 0,
},
"Sales Taxes and Charges": {"doctype": "Sales Taxes and Charges", "add_if_empty": True},
"Sales Team": {"doctype": "Sales Team", "add_if_empty": True},
Expand Down

0 comments on commit 035ef03

Please sign in to comment.