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

feat: forward backward linking to sales order #1539

Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ def get_data():
},
'internal_links': {
'Material Request': ['items', 'material_request'],
'Sales Order': ['items', 'sales_order'],
'Production Plan': ['items', 'production_plan'],
'Supplier Quotation': ['items', 'supplier_quotation'],
'Project': ['items', 'project'],
'Project': ['items', 'project']
},
'transactions': [
{
Expand All @@ -25,7 +27,7 @@ def get_data():
},
{
'label': _('Reference'),
'items': ['Material Request', 'Supplier Quotation', 'Project', 'Auto Repeat']
'items': ['Material Request', 'Sales Order', 'Production Plan', 'Supplier Quotation', 'Project', 'Auto Repeat']
},
{
'label': _('Sub-contracting'),
Expand Down
22 changes: 13 additions & 9 deletions erpnext/manufacturing/doctype/production_plan/production_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ def download_raw_materials(production_plan):

build_csv_response(item_list, doc.name)

def get_exploded_items(item_details, company, bom_no, include_non_stock_items, planned_qty=1):
def get_exploded_items(item_details, company, bom_no, include_non_stock_items, planned_qty=1, sales_order=None):
for d in frappe.db.sql("""select bei.item_code, item.default_bom as bom,
ifnull(sum(bei.stock_qty/ifnull(bom.quantity, 1)), 0)*%s as qty, item.item_name,
bei.description, bei.stock_uom, item.min_order_qty, bei.source_warehouse,
Expand All @@ -488,14 +488,16 @@ def get_exploded_items(item_details, company, bom_no, include_non_stock_items, p
and bom.name=%s and item.is_stock_item in (1, {0})
group by bei.item_code, bei.stock_uom""".format(0 if include_non_stock_items else 1),
(planned_qty, company, bom_no), as_dict=1):
item_details.setdefault(d.get('item_code'), d)
d['sales_order'] = sales_order
item_details.setdefault(d.get('item_code'), d)
return item_details

def get_exploded_items_with_subassembly(item_details, company, bom_no, include_non_stock_items, planned_qty=1):
def get_exploded_items_with_subassembly(item_details, company, bom_no, include_non_stock_items, planned_qty=1, sales_order=None):
explosion_items = get_items_for_explode_and_subassembly("BOM Explosion Item", company, bom_no, include_non_stock_items, planned_qty)
bom_items = get_items_for_explode_and_subassembly("BOM Item", company, bom_no, include_non_stock_items, planned_qty)

for d in explosion_items + bom_items:
item_details['sales_order'] = sales_order
item_details.setdefault(d.get('item_code'), d)
return item_details

Expand All @@ -521,7 +523,7 @@ def get_items_for_explode_and_subassembly(item, company, bom_no, include_non_sto
return items

def get_subitems(doc, data, item_details, bom_no, company, include_non_stock_items,
include_subcontracted_items, parent_qty, planned_qty=1):
include_subcontracted_items, parent_qty, planned_qty=1, sales_order=None):
items = frappe.db.sql("""
SELECT
bom_item.item_code, default_material_request_type, item.item_name,
Expand Down Expand Up @@ -562,6 +564,7 @@ def get_subitems(doc, data, item_details, bom_no, company, include_non_stock_ite
if d.qty > 0:
get_subitems(doc, data, item_details, d.default_bom, company,
include_non_stock_items, include_subcontracted_items, d.qty)
item_details['sales_order'] = sales_order
return item_details

def get_material_request_items(row, sales_order,
Expand Down Expand Up @@ -602,7 +605,7 @@ def get_material_request_items(row, sales_order,
'projected_qty': bin_dict.get("projected_qty", 0),
'min_order_qty': row['min_order_qty'],
'material_request_type': row.get("default_material_request_type"),
'sales_order': sales_order,
'sales_order': row.get("sales_order"),
'description': row.get("description"),
'uom': row.get("purchase_uom") or row.get("stock_uom")
}
Expand Down Expand Up @@ -705,14 +708,14 @@ def get_items_for_material_requests(doc, ignore_existing_ordered_qty=None):
if data.get('include_exploded_items') and include_subcontracted_items and not doc.get("include_sub_assembly_with_exploded_item"):
# fetch exploded items from BOM
item_details = get_exploded_items(item_details,
company, bom_no, include_non_stock_items, planned_qty=planned_qty)
elif data.get('include_exploded_items') and include_subcontracted_items and doc.get("include_sub_assembly_with_exploded_item"):
company, bom_no, include_non_stock_items, planned_qty=planned_qty, sales_order=data.get("sales_order"))
elif data.get('include_exploded_items') and include_subcontracted_items and doc.get("include_sub_assembly_with_exploded_item"):
# fetch exploded items with sub assembly item from BOM
item_details = get_exploded_items_with_subassembly(item_details,
company, bom_no, include_non_stock_items, planned_qty=planned_qty)
company, bom_no, include_non_stock_items, planned_qty=planned_qty, sales_order=data.get("sales_order"))
else:
item_details = get_subitems(doc, data, item_details, bom_no, company,
include_non_stock_items, include_subcontracted_items, 1, planned_qty=planned_qty)
include_non_stock_items, include_subcontracted_items, 1, planned_qty=planned_qty, sales_order=data.get("sales_order"))
elif data.get('item_code'):
item_master = frappe.get_doc('Item', data['item_code']).as_dict()
purchase_uom = item_master.purchase_uom or item_master.stock_uom
Expand All @@ -735,6 +738,7 @@ def get_items_for_material_requests(doc, ignore_existing_ordered_qty=None):
'description' : item_master.description,
'stock_uom' : item_master.stock_uom,
'conversion_factor' : conversion_factor,
'sales_order': data.get("sales_order")
}
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,17 @@
def get_data():
return {
'fieldname': 'production_plan',
'internal_links': {
'Sales Order': ['po_items', 'sales_order']
},
'transactions': [
{
'label': _('Transactions'),
'items': ['Work Order', 'Material Request']
},
{
'label': _('Reference'),
'items': ['Sales Order']
},
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
def get_data():
return {
'fieldname': 'material_request',
'internal_links': {
'Sales Order': ['items', 'sales_order'],
'Production Plan': ['items', 'production_plan'],
},
'transactions': [
{
'label': _('Related'),
Expand All @@ -13,6 +17,10 @@ def get_data():
{
'label': _('Manufacturing'),
'items': ['Work Order']
}
},
{
'label': _('Reference'),
'items': ['Sales Order', 'Production Plan']
},
]
}