Merge pull request #31493 from deepeshgarg007/internal_invoicing_references
fix: Internal PI link in Sales Invoice
This commit is contained in:
commit
a4edcfe33b
@ -2117,6 +2117,8 @@ def make_inter_company_transaction(doctype, source_name, target_doc=None):
|
|||||||
source_document_warehouse_field = "from_warehouse"
|
source_document_warehouse_field = "from_warehouse"
|
||||||
target_document_warehouse_field = "target_warehouse"
|
target_document_warehouse_field = "target_warehouse"
|
||||||
|
|
||||||
|
received_items = get_received_items(source_name, target_doctype, target_detail_field)
|
||||||
|
|
||||||
validate_inter_company_transaction(source_doc, doctype)
|
validate_inter_company_transaction(source_doc, doctype)
|
||||||
details = get_inter_company_details(source_doc, doctype)
|
details = get_inter_company_details(source_doc, doctype)
|
||||||
|
|
||||||
@ -2181,12 +2183,17 @@ def make_inter_company_transaction(doctype, source_name, target_doc=None):
|
|||||||
shipping_address_name=target_doc.shipping_address_name,
|
shipping_address_name=target_doc.shipping_address_name,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def update_item(source, target, source_parent):
|
||||||
|
target.qty = flt(source.qty) - received_items.get(source.name, 0.0)
|
||||||
|
|
||||||
item_field_map = {
|
item_field_map = {
|
||||||
"doctype": target_doctype + " Item",
|
"doctype": target_doctype + " Item",
|
||||||
"field_no_map": ["income_account", "expense_account", "cost_center", "warehouse"],
|
"field_no_map": ["income_account", "expense_account", "cost_center", "warehouse"],
|
||||||
"field_map": {
|
"field_map": {
|
||||||
"rate": "rate",
|
"rate": "rate",
|
||||||
},
|
},
|
||||||
|
"postprocess": update_item,
|
||||||
|
"condition": lambda doc: doc.qty > 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
if doctype in ["Sales Invoice", "Sales Order"]:
|
if doctype in ["Sales Invoice", "Sales Order"]:
|
||||||
@ -2224,6 +2231,28 @@ def make_inter_company_transaction(doctype, source_name, target_doc=None):
|
|||||||
return doclist
|
return doclist
|
||||||
|
|
||||||
|
|
||||||
|
def get_received_items(reference_name, doctype, reference_fieldname):
|
||||||
|
target_doctypes = frappe.get_all(
|
||||||
|
doctype,
|
||||||
|
filters={"inter_company_invoice_reference": reference_name, "docstatus": 1},
|
||||||
|
as_list=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
if target_doctypes:
|
||||||
|
target_doctypes = list(target_doctypes[0])
|
||||||
|
|
||||||
|
received_items_map = frappe._dict(
|
||||||
|
frappe.get_all(
|
||||||
|
doctype + " Item",
|
||||||
|
filters={"parent": ("in", target_doctypes)},
|
||||||
|
fields=[reference_fieldname, "qty"],
|
||||||
|
as_list=1,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
return received_items_map
|
||||||
|
|
||||||
|
|
||||||
def set_purchase_references(doc):
|
def set_purchase_references(doc):
|
||||||
# add internal PO or PR links if any
|
# add internal PO or PR links if any
|
||||||
if doc.is_internal_transfer():
|
if doc.is_internal_transfer():
|
||||||
|
@ -11,6 +11,7 @@ def get_data():
|
|||||||
"Payment Request": "reference_name",
|
"Payment Request": "reference_name",
|
||||||
"Sales Invoice": "return_against",
|
"Sales Invoice": "return_against",
|
||||||
"Auto Repeat": "reference_document",
|
"Auto Repeat": "reference_document",
|
||||||
|
"Purchase Invoice": "inter_company_invoice_reference",
|
||||||
},
|
},
|
||||||
"internal_links": {
|
"internal_links": {
|
||||||
"Sales Order": ["items", "sales_order"],
|
"Sales Order": ["items", "sales_order"],
|
||||||
@ -30,5 +31,6 @@ def get_data():
|
|||||||
{"label": _("Reference"), "items": ["Timesheet", "Delivery Note", "Sales Order"]},
|
{"label": _("Reference"), "items": ["Timesheet", "Delivery Note", "Sales Order"]},
|
||||||
{"label": _("Returns"), "items": ["Sales Invoice"]},
|
{"label": _("Returns"), "items": ["Sales Invoice"]},
|
||||||
{"label": _("Subscription"), "items": ["Auto Repeat"]},
|
{"label": _("Subscription"), "items": ["Auto Repeat"]},
|
||||||
|
{"label": _("Internal Transfers"), "items": ["Purchase Invoice"]},
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user