From c48efaba6e0cdea0c42340bd086b5cf38f8c41c8 Mon Sep 17 00:00:00 2001 From: deepeshgarg007 Date: Thu, 24 Jan 2019 17:15:38 +0530 Subject: [PATCH 1/3] fix(sales_invoice): fetch customer price list if available before pos profile price list --- .../doctype/sales_invoice/sales_invoice.js | 4 ++++ .../doctype/sales_invoice/sales_invoice.py | 7 ++++++- erpnext/accounts/party.py | 20 ++++++++++++++----- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js index 91a44b377d..8911ddf464 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js @@ -217,6 +217,9 @@ erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.exte this.get_terms(); }, customer: function() { + if (this.frm.doc.is_pos){ + var pos_profile = this.frm.doc.pos_profile; + } var me = this; if(this.frm.updating_party_details) return; erpnext.utils.get_party_details(this.frm, @@ -226,6 +229,7 @@ erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.exte party_type: "Customer", account: this.frm.doc.debit_to, price_list: this.frm.doc.selling_price_list, + pos_profile: pos_profile }, function() { me.apply_pricing_rule(); }); diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index 6072fb895c..895ca07da2 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -398,11 +398,16 @@ class SalesInvoice(SellingController): self.account_for_change_amount = pos.get('account_for_change_amount') for fieldname in ('territory', 'naming_series', 'currency', 'taxes_and_charges', 'letter_head', 'tc_name', - 'selling_price_list', 'company', 'select_print_heading', 'cash_bank_account', 'company_address', + 'company', 'select_print_heading', 'cash_bank_account', 'company_address', 'write_off_account', 'write_off_cost_center', 'apply_discount_on'): if (not for_validate) or (for_validate and not self.get(fieldname)): self.set(fieldname, pos.get(fieldname)) + customer_price_list = frappe.get_value("Customer", self.customer, 'default_price_list') + + if not customer_price_list: + self.set('selling_price_list', pos.get('selling_price_list')) + if not for_validate: self.update_stock = cint(pos.get("update_stock")) diff --git a/erpnext/accounts/party.py b/erpnext/accounts/party.py index 1e1f8b5b83..c0a44d1c02 100644 --- a/erpnext/accounts/party.py +++ b/erpnext/accounts/party.py @@ -22,18 +22,20 @@ class DuplicatePartyAccountError(frappe.ValidationError): pass @frappe.whitelist() def get_party_details(party=None, account=None, party_type="Customer", company=None, posting_date=None, - bill_date=None, price_list=None, currency=None, doctype=None, ignore_permissions=False, fetch_payment_terms_template=True, party_address=None, shipping_address=None): + bill_date=None, price_list=None, currency=None, doctype=None, ignore_permissions=False, fetch_payment_terms_template=True, + party_address=None, shipping_address=None, pos_profile=None): if not party: return {} if not frappe.db.exists(party_type, party): frappe.throw(_("{0}: {1} does not exists").format(party_type, party)) return _get_party_details(party, account, party_type, - company, posting_date, bill_date, price_list, currency, doctype, ignore_permissions, fetch_payment_terms_template, party_address, shipping_address) + company, posting_date, bill_date, price_list, currency, doctype, ignore_permissions, + fetch_payment_terms_template, party_address, shipping_address, pos_profile) def _get_party_details(party=None, account=None, party_type="Customer", company=None, posting_date=None, bill_date=None, price_list=None, currency=None, doctype=None, ignore_permissions=False, - fetch_payment_terms_template=True, party_address=None, shipping_address=None): + fetch_payment_terms_template=True, party_address=None, shipping_address=None, pos_profile=None): out = frappe._dict(set_account_and_due_date(party, account, party_type, company, posting_date, bill_date, doctype)) party = out[party_type.lower()] @@ -49,7 +51,7 @@ def _get_party_details(party=None, account=None, party_type="Customer", company= set_address_details(out, party, party_type, doctype, company, party_address, shipping_address) set_contact_details(out, party, party_type) set_other_values(out, party, party_type) - set_price_list(out, party, party_type, price_list) + set_price_list(out, party, party_type, price_list, pos_profile) out["taxes_and_charges"] = set_taxes(party.name, party_type, posting_date, company, out.customer_group, out.supplier_type) @@ -149,12 +151,20 @@ def get_default_price_list(party): return None -def set_price_list(out, party, party_type, given_price_list): +def set_price_list(out, party, party_type, given_price_list, pos=None): # price list price_list = get_permitted_documents('Price List') if price_list: price_list = price_list[0] + elif pos and party_type == 'Customer': + customer_price_list = frappe.get_value('Customer', party.name, 'default_price_list') + + if customer_price_list: + price_list = customer_price_list + else: + pos_price_list = frappe.get_value('Pos Profile', pos, 'selling_price_list') + price_list = pos_price_list else: price_list = get_default_price_list(party) or given_price_list From 1f9a6febdd138a1a9b1b1651c8f21e8d14d4416d Mon Sep 17 00:00:00 2001 From: deepeshgarg007 Date: Fri, 25 Jan 2019 11:53:55 +0530 Subject: [PATCH 2/3] fix: Assign given price list if POS price list is not available --- erpnext/accounts/party.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/accounts/party.py b/erpnext/accounts/party.py index c0a44d1c02..f412506a7c 100644 --- a/erpnext/accounts/party.py +++ b/erpnext/accounts/party.py @@ -164,7 +164,7 @@ def set_price_list(out, party, party_type, given_price_list, pos=None): price_list = customer_price_list else: pos_price_list = frappe.get_value('Pos Profile', pos, 'selling_price_list') - price_list = pos_price_list + price_list = pos_price_list or given_price_list else: price_list = get_default_price_list(party) or given_price_list From 8c84b7b8884746966b735a187d681c4253eef6ed Mon Sep 17 00:00:00 2001 From: deepeshgarg007 Date: Fri, 25 Jan 2019 16:44:45 +0530 Subject: [PATCH 3/3] fix: Doctype Name correction --- erpnext/accounts/party.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/accounts/party.py b/erpnext/accounts/party.py index f412506a7c..5855ac3bcd 100644 --- a/erpnext/accounts/party.py +++ b/erpnext/accounts/party.py @@ -163,7 +163,7 @@ def set_price_list(out, party, party_type, given_price_list, pos=None): if customer_price_list: price_list = customer_price_list else: - pos_price_list = frappe.get_value('Pos Profile', pos, 'selling_price_list') + pos_price_list = frappe.get_value('POS Profile', pos, 'selling_price_list') price_list = pos_price_list or given_price_list else: price_list = get_default_price_list(party) or given_price_list