Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Update Values before after_mapping hook is called #42682

Merged
merged 3 commits into from
Oct 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 23 additions & 22 deletions erpnext/buying/doctype/purchase_order/purchase_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,28 @@ def make_subcontracting_order(source_name, target_doc=None, save=False, submit=F


def get_mapped_subcontracting_order(source_name, target_doc=None):
def post_process(source_doc, target_doc):
target_doc.populate_items_table()

if target_doc.set_warehouse:
for item in target_doc.items:
item.warehouse = target_doc.set_warehouse
else:
if source_doc.set_warehouse:
for item in target_doc.items:
item.warehouse = source_doc.set_warehouse
else:
for idx, item in enumerate(target_doc.items):
item.warehouse = source_doc.items[idx].warehouse

for idx, item in enumerate(target_doc.items):
item.job_card = source_doc.items[idx].job_card
if not target_doc.supplier_warehouse:
# WIP warehouse is set as Supplier Warehouse in Job Card
target_doc.supplier_warehouse = frappe.get_cached_value(
"Job Card", item.job_card, "wip_warehouse"
)

if target_doc and isinstance(target_doc, str):
target_doc = json.loads(target_doc)
for key in ["service_items", "items", "supplied_items"]:
Expand Down Expand Up @@ -911,30 +933,9 @@ def get_mapped_subcontracting_order(source_name, target_doc=None):
},
},
target_doc,
post_process,
)

target_doc.populate_items_table()
source_doc = frappe.get_doc("Purchase Order", source_name)

if target_doc.set_warehouse:
for item in target_doc.items:
item.warehouse = target_doc.set_warehouse
else:
if source_doc.set_warehouse:
for item in target_doc.items:
item.warehouse = source_doc.set_warehouse
else:
for idx, item in enumerate(target_doc.items):
item.warehouse = source_doc.items[idx].warehouse

for idx, item in enumerate(target_doc.items):
item.job_card = source_doc.items[idx].job_card
if not target_doc.supplier_warehouse:
# WIP warehouse is set as Supplier Warehouse in Job Card
target_doc.supplier_warehouse = frappe.get_cached_value(
"Job Card", item.job_card, "wip_warehouse"
)

return target_doc


Expand Down
Loading