From d43bb4db41d556056b72d73b80f2ea4571a14721 Mon Sep 17 00:00:00 2001 From: Saqib Date: Mon, 11 Jan 2021 12:59:35 +0530 Subject: [PATCH] fix(pos): error while merging pos invoices into sales invoice (#24337) --- .../doctype/pos_closing_entry/pos_closing_entry.py | 6 +++++- .../pos_invoice_merge_log/pos_invoice_merge_log.py | 11 ++++++----- erpnext/controllers/sales_and_purchase_return.py | 1 + erpnext/patches.txt | 1 + .../patches/v13_0/create_uae_pos_invoice_fields.py | 14 ++++++++++++++ 5 files changed, 27 insertions(+), 6 deletions(-) create mode 100644 erpnext/patches/v13_0/create_uae_pos_invoice_fields.py diff --git a/erpnext/accounts/doctype/pos_closing_entry/pos_closing_entry.py b/erpnext/accounts/doctype/pos_closing_entry/pos_closing_entry.py index 2b91c74ce6d..c26e14ff6f8 100644 --- a/erpnext/accounts/doctype/pos_closing_entry/pos_closing_entry.py +++ b/erpnext/accounts/doctype/pos_closing_entry/pos_closing_entry.py @@ -57,7 +57,11 @@ class POSClosingEntry(Document): if not invalid_rows: return - error_list = [_("Row #{}: {}").format(row.get('idx'), row.get('msg')) for row in invalid_rows] + error_list = [] + for row in invalid_rows: + for msg in row.get('msg'): + error_list.append(_("Row #{}: {}").format(row.get('idx'), msg)) + frappe.throw(error_list, title=_("Invalid POS Invoices"), as_list=True) def on_submit(self): diff --git a/erpnext/accounts/doctype/pos_invoice_merge_log/pos_invoice_merge_log.py b/erpnext/accounts/doctype/pos_invoice_merge_log/pos_invoice_merge_log.py index add27e9dffb..5e43cfe0302 100644 --- a/erpnext/accounts/doctype/pos_invoice_merge_log/pos_invoice_merge_log.py +++ b/erpnext/accounts/doctype/pos_invoice_merge_log/pos_invoice_merge_log.py @@ -5,10 +5,10 @@ from __future__ import unicode_literals import frappe from frappe import _ -from frappe.utils import cint, flt, add_months, today, date_diff, getdate, add_days, cstr, nowdate -from frappe.model.document import Document -from frappe.model.mapper import map_doc from frappe.model import default_fields +from frappe.model.document import Document +from frappe.model.mapper import map_doc, map_child_doc +from frappe.utils import cint, flt, add_months, today, date_diff, getdate, add_days, cstr, nowdate from six import iteritems @@ -83,7 +83,7 @@ class POSInvoiceMergeLog(Document): credit_note.is_consolidated = 1 # TODO: return could be against multiple sales invoice which could also have been consolidated? - credit_note.return_against = self.consolidated_invoice + # credit_note.return_against = self.consolidated_invoice credit_note.save() credit_note.submit() self.consolidated_credit_note = credit_note.name @@ -111,7 +111,8 @@ class POSInvoiceMergeLog(Document): i.qty = i.qty + item.qty if not found: item.rate = item.net_rate - items.append(item) + si_item = map_child_doc(item, invoice, {"doctype": "Sales Invoice Item"}) + items.append(si_item) for tax in doc.get('taxes'): found = False diff --git a/erpnext/controllers/sales_and_purchase_return.py b/erpnext/controllers/sales_and_purchase_return.py index 79792262c0a..85af0eaedf6 100644 --- a/erpnext/controllers/sales_and_purchase_return.py +++ b/erpnext/controllers/sales_and_purchase_return.py @@ -262,6 +262,7 @@ def make_return_doc(doctype, source_name, target_doc=None): if doc.get("is_return"): if doc.doctype == 'Sales Invoice' or doc.doctype == 'POS Invoice': + doc.consolidated_invoice = "" doc.set('payments', []) for data in source.payments: paid_amount = 0.00 diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 894ee82b4ca..ca8e01c5158 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -743,3 +743,4 @@ erpnext.patches.v13_0.updates_for_multi_currency_payroll erpnext.patches.v13_0.create_leave_policy_assignment_based_on_employee_current_leave_policy erpnext.patches.v13_0.add_po_to_global_search erpnext.patches.v13_0.update_returned_qty_in_pr_dn +erpnext.patches.v13_0.create_uae_pos_invoice_fields \ No newline at end of file diff --git a/erpnext/patches/v13_0/create_uae_pos_invoice_fields.py b/erpnext/patches/v13_0/create_uae_pos_invoice_fields.py new file mode 100644 index 00000000000..48d5cb4cc8f --- /dev/null +++ b/erpnext/patches/v13_0/create_uae_pos_invoice_fields.py @@ -0,0 +1,14 @@ +# Copyright (c) 2019, Frappe and Contributors +# License: GNU General Public License v3. See license.txt + +from __future__ import unicode_literals + +import frappe +from erpnext.regional.united_arab_emirates.setup import make_custom_fields + +def execute(): + company = frappe.get_all('Company', filters = {'country': ['in', ['Saudi Arabia', 'United Arab Emirates']]}) + if not company: + return + + make_custom_fields() \ No newline at end of file