Skip to content

Commit

Permalink
fix: set_missing_values in SE and re-use the same on all SE mappings
Browse files Browse the repository at this point in the history
- `set_missing_values` in SE will set actual qty, transfer qty and calculate rate/amount
- Re-use `set_missing_values` wherever SE is doc is being mapped

(cherry picked from commit 90a8e92)
  • Loading branch information
marination authored and mergify[bot] committed May 11, 2022
1 parent 678a01d commit fe52c1f
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 8 deletions.
4 changes: 3 additions & 1 deletion erpnext/buying/doctype/purchase_order/purchase_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,8 @@ def make_rm_stock_entry(purchase_order, rm_items):
}
}
stock_entry.add_to_stock_entry_detail(items_dict)

stock_entry.set_missing_values()
return stock_entry.as_dict()
else:
frappe.throw(_("No Items selected for transfer"))
Expand Down Expand Up @@ -724,7 +726,7 @@ def make_return_stock_entry_for_subcontract(available_materials, po_doc, po_deta
add_items_in_ste(ste_doc, value, value.qty, po_details)

ste_doc.set_stock_entry_type()
ste_doc.calculate_rate_and_amount()
ste_doc.set_missing_values()

return ste_doc

Expand Down
2 changes: 0 additions & 2 deletions erpnext/manufacturing/doctype/job_card/job_card.py
Original file line number Diff line number Diff line change
Expand Up @@ -764,8 +764,6 @@ def set_missing_values(source, target):
pending_fg_qty = flt(source.get("for_quantity", 0)) - flt(source.get("transferred_qty", 0))
target.fg_completed_qty = pending_fg_qty if pending_fg_qty > 0 else 0

target.set_transfer_qty()
target.calculate_rate_and_amount()
target.set_missing_values()
target.set_stock_entry_type()

Expand Down
4 changes: 2 additions & 2 deletions erpnext/public/js/controllers/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -1496,15 +1496,15 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
var me = this;
var args = this._get_args(item);
if (!(args.items && args.items.length)) {
if(calculate_taxes_and_totals) me.calculate_taxes_and_totals();
if (calculate_taxes_and_totals) me.calculate_taxes_and_totals();
return;
}

// Target doc created from a mapped doc
if (this.frm.doc.__onload && this.frm.doc.__onload.ignore_price_list) {
// Calculate totals even though pricing rule is not applied.
// `apply_pricing_rule` is triggered due to change in data which most likely contributes to Total.
if(calculate_taxes_and_totals) me.calculate_taxes_and_totals();
if (calculate_taxes_and_totals) me.calculate_taxes_and_totals();
return;
}

Expand Down
1 change: 1 addition & 0 deletions erpnext/stock/doctype/batch/batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ def split_batch(batch_no, item_code, warehouse, qty, new_batch_id=None):
)
)
stock_entry.set_stock_entry_type()
stock_entry.set_missing_values()
stock_entry.insert()
stock_entry.submit()

Expand Down
2 changes: 1 addition & 1 deletion erpnext/stock/doctype/material_request/material_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ def set_missing_values(source, target):
if source.material_request_type == "Customer Provided":
target.purpose = "Material Receipt"

target.run_method("calculate_rate_and_amount")
target.set_missing_values()
target.set_stock_entry_type()
target.set_job_card_data()

Expand Down
3 changes: 1 addition & 2 deletions erpnext/stock/doctype/pick_list/pick_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -671,8 +671,7 @@ def create_stock_entry(pick_list):
else:
stock_entry = update_stock_entry_items_with_no_reference(pick_list, stock_entry)

stock_entry.set_actual_qty()
stock_entry.calculate_rate_and_amount()
stock_entry.set_missing_values()

return stock_entry.as_dict()

Expand Down
1 change: 1 addition & 0 deletions erpnext/stock/doctype/purchase_receipt/purchase_receipt.py
Original file line number Diff line number Diff line change
Expand Up @@ -993,6 +993,7 @@ def make_stock_entry(source_name, target_doc=None):
def set_missing_values(source, target):
target.stock_entry_type = "Material Transfer"
target.purpose = "Material Transfer"
target.set_missing_values()

doclist = get_mapped_doc(
"Purchase Receipt",
Expand Down
7 changes: 7 additions & 0 deletions erpnext/stock/doctype/stock_entry/stock_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -2196,6 +2196,12 @@ def get_available_serial_nos(self, stock_entries):

return sorted(list(set(get_serial_nos(self.pro_doc.serial_no)) - set(used_serial_nos)))

def set_missing_values(self):
"Updates rate and availability of all the items of mapped doc."
self.set_transfer_qty()
self.set_actual_qty()
self.calculate_rate_and_amount()


@frappe.whitelist()
def move_sample_to_retention_warehouse(company, items):
Expand Down Expand Up @@ -2245,6 +2251,7 @@ def move_sample_to_retention_warehouse(company, items):
def make_stock_in_entry(source_name, target_doc=None):
def set_missing_values(source, target):
target.set_stock_entry_type()
target.set_missing_values()

def update_item(source_doc, target_doc, source_parent):
target_doc.t_warehouse = ""
Expand Down
2 changes: 2 additions & 0 deletions erpnext/stock/doctype/stock_entry/stock_entry_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ def process_serial_numbers(serial_nos_list):
)

s.set_stock_entry_type()
s.set_missing_values()

if not args.do_not_save:
s.insert()
if not args.do_not_submit:
Expand Down

0 comments on commit fe52c1f

Please sign in to comment.