From 047bf3833e402b119cfd951b4aa612d154b8252f Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Fri, 4 Dec 2020 11:02:05 +0530 Subject: [PATCH] fix: Account naming changes and other fixes --- .../purchase_invoice/purchase_invoice.js | 2 +- .../purchase_invoice/purchase_invoice.json | 8 ++++---- .../purchase_invoice/purchase_invoice.py | 18 ++++++++++-------- .../doctype/sales_invoice/sales_invoice.js | 2 +- .../doctype/sales_invoice/sales_invoice.json | 10 +++++----- .../doctype/sales_invoice/sales_invoice.py | 14 ++++++++------ erpnext/buying/doctype/supplier/supplier.py | 6 ++++++ erpnext/selling/doctype/customer/customer.py | 6 ++++++ erpnext/setup/doctype/company/company.js | 2 +- erpnext/setup/doctype/company/company.json | 8 ++++---- 10 files changed, 46 insertions(+), 30 deletions(-) diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js index 48b461448a7..b70dc5c7719 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js @@ -16,7 +16,7 @@ erpnext.accounts.PurchaseInvoice = erpnext.buying.BuyingController.extend({ }); } - this.frm.set_query("inter_company_account", function() { + this.frm.set_query("unrealized_profit_loss_account", function() { return { filters: { company: doc.company, diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json index 369f3d0e158..e262f73ebbe 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json @@ -152,7 +152,7 @@ "is_opening", "against_expense_account", "column_break_63", - "inter_company_account", + "unrealized_profit_loss_account", "status", "inter_company_invoice_reference", "is_internal_supplier", @@ -1342,9 +1342,9 @@ }, { "depends_on": "eval:doc.is_internal_supplier", - "fieldname": "inter_company_account", + "fieldname": "unrealized_profit_loss_account", "fieldtype": "Link", - "label": "Inter Company Account", + "label": "Unrealized Profit / Loss Account", "options": "Account" }, { @@ -1360,7 +1360,7 @@ "idx": 204, "is_submittable": 1, "links": [], - "modified": "2020-11-27 19:47:04.827315", + "modified": "2020-11-29 19:47:04.827315", "modified_by": "Administrator", "module": "Accounts", "name": "Purchase Invoice", diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py index cf78e000eac..3e7fbb7834b 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py @@ -202,8 +202,8 @@ class PurchaseInvoice(BuyingController): ["Purchase Receipt", "purchase_receipt", "pr_detail"] ]) - def validate_warehouse(self): - if self.update_stock: + def validate_warehouse(self, for_validate=True): + if self.update_stock and for_validate: for d in self.get('items'): if not d.warehouse: frappe.throw(_("Warehouse required at Row No {0}, please set default warehouse for the item {1} for the company {2}"). @@ -229,7 +229,7 @@ class PurchaseInvoice(BuyingController): if self.update_stock: self.validate_item_code() - self.validate_warehouse() + self.validate_warehouse(for_validate) if auto_accounting_for_stock: warehouse_account = get_warehouse_account_map(self.company) @@ -379,14 +379,16 @@ class PurchaseInvoice(BuyingController): representation company is same """ - if self.is_internal_transfer() and not self.inter_company_account: - inter_company_account = frappe.get_cached_value('Company', self.company, 'default_inter_company_account') + if self.is_internal_transfer() and not self.unrealized_profit_loss_account: + unrealized_profit_loss_account = frappe.db.get_value('Company', self.company, 'unrealized_profit_loss_account') - if not inter_company_account: + if not unrealized_profit_loss_account: msg = _("Please select inter-company account or add default inter-company account for company {0}").format( frappe.bold(self.company)) frappe.throw(msg) + self.unrealized_profit_loss_account = unrealized_profit_loss_account + def is_internal_transfer(self): """ It will an internal transfer if its an internal supplier and representation @@ -902,10 +904,10 @@ class PurchaseInvoice(BuyingController): def make_internal_transfer_gl_entries(self, gl_entries): if self.is_internal_transfer() and flt(self.base_total_taxes_and_charges): - account_currency = get_account_currency(self.inter_company_account) + account_currency = get_account_currency(self.unrealized_profit_loss_account) gl_entries.append( self.get_gl_dict({ - "account": self.inter_company_account, + "account": self.unrealized_profit_loss_account, "against": self.supplier, "credit": flt(self.total_taxes_and_charges), "credit_in_account_currency": flt(self.base_total_taxes_and_charges), diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js index 056928e21e3..4f2cbc88efb 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js @@ -584,7 +584,7 @@ frappe.ui.form.on('Sales Invoice', { }; }); - frm.set_query("inter_company_account", function() { + frm.set_query("unrealized_profit_loss_account", function() { return { filters: { company: frm.doc.company, diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.json b/erpnext/accounts/doctype/sales_invoice/sales_invoice.json index 7d2c4a67125..d3a80e19ca8 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.json +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.json @@ -171,7 +171,7 @@ "c_form_applicable", "c_form_no", "column_break8", - "inter_company_account", + "unrealized_profit_loss_account", "remarks", "sales_team_section_break", "sales_partner", @@ -1954,14 +1954,14 @@ }, { "depends_on": "eval:doc.is_internal_customer", - "fieldname": "inter_company_account", + "fieldname": "unrealized_profit_loss_account", "fieldtype": "Link", - "label": "Inter Company Account", + "label": "Unrealized Profit / Loss Account", "options": "Account" }, { "depends_on": "eval:doc.is_internal_customer", - "fetch_from": "cusstomer.represents_company", + "fetch_from": "customer.represents_company", "fieldname": "represents_company", "fieldtype": "Link", "label": "Represents Company", @@ -1973,7 +1973,7 @@ "idx": 181, "is_submittable": 1, "links": [], - "modified": "2020-11-27 18:48:15.012300", + "modified": "2020-11-29 18:48:15.012300", "modified_by": "Administrator", "module": "Accounts", "name": "Sales Invoice", diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index 0aaf78aeedc..cbb0a7e1151 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -578,14 +578,16 @@ class SalesInvoice(SellingController): representation company is same """ - if self.is_internal_transfer() and not self.inter_company_account: - inter_company_account = frappe.get_cached_value('Company', self.company, 'default_inter_company_account') + if self.is_internal_transfer() and not self.unrealized_profit_loss_account: + unrealized_profit_loss_account = frappe.db.get_value('Company', self.company, 'unrealized_profit_loss_account') - if not inter_company_account: - msg = _("Please select inter-company account or add default inter-company account for company {0}").format( + if not unrealized_profit_loss_account: + msg = _("Please select Unrealized Profit / Loss account or add default Unrealized Profit / Loss account account for company {0}").format( frappe.bold(self.company)) frappe.throw(msg) + self.unrealized_profit_loss_account = unrealized_profit_loss_account + def is_internal_transfer(self): """ It will an internal transfer if its an internal customer and representation @@ -838,10 +840,10 @@ class SalesInvoice(SellingController): def make_internal_transfer_gl_entries(self, gl_entries): if self.is_internal_transfer() and flt(self.base_total_taxes_and_charges): - account_currency = get_account_currency(self.inter_company_account) + account_currency = get_account_currency(self.unrealized_profit_loss_account) gl_entries.append( self.get_gl_dict({ - "account": self.inter_company_account, + "account": self.unrealized_profit_loss_account, "against": self.customer, "debit": flt(self.total_taxes_and_charges), "debit_in_account_currency": flt(self.base_total_taxes_and_charges), diff --git a/erpnext/buying/doctype/supplier/supplier.py b/erpnext/buying/doctype/supplier/supplier.py index df143eefa0d..0ee9d180d99 100644 --- a/erpnext/buying/doctype/supplier/supplier.py +++ b/erpnext/buying/doctype/supplier/supplier.py @@ -49,6 +49,12 @@ class Supplier(TransactionBase): msgprint(_("Series is mandatory"), raise_exception=1) validate_party_accounts(self) + self.validate_internal_supplier() + + def validate_internal_supplier(self): + if self.is_internal_supplier and frappe.db.get_value("Supplier", {"represents_company": self.represents_company}, "name"): + frappe.throw(_("Internal Supplier for company {0} already exists").format( + frappe.bold(self.represents_company))) def on_trash(self): delete_contact_and_address('Supplier', self.name) diff --git a/erpnext/selling/doctype/customer/customer.py b/erpnext/selling/doctype/customer/customer.py index 0172d9c128f..f9030b57b69 100644 --- a/erpnext/selling/doctype/customer/customer.py +++ b/erpnext/selling/doctype/customer/customer.py @@ -58,6 +58,7 @@ class Customer(TransactionBase): self.set_loyalty_program() self.check_customer_group_change() self.validate_default_bank_account() + self.validate_internal_customer() # set loyalty program tier if frappe.db.exists('Customer', self.name): @@ -82,6 +83,11 @@ class Customer(TransactionBase): if not is_company_account: frappe.throw(_("{0} is not a company bank account").format(frappe.bold(self.default_bank_account))) + def validate_internal_customer(self): + if self.is_internal_customer and frappe.db.get_value('Customer', {"represents_company": self.represents_company}, "name"): + frappe.throw(_("Internal Customer for company {0} already exists").format( + frappe.bold(self.represents_company))) + def on_update(self): self.validate_name_with_customer_group() self.create_primary_contact() diff --git a/erpnext/setup/doctype/company/company.js b/erpnext/setup/doctype/company/company.js index 96d01cbc99e..f2122cae9d1 100644 --- a/erpnext/setup/doctype/company/company.js +++ b/erpnext/setup/doctype/company/company.js @@ -263,7 +263,7 @@ erpnext.company.setup_queries = function(frm) { ["expenses_included_in_asset_valuation", {"account_type": "Expenses Included In Asset Valuation"}], ["capital_work_in_progress_account", {"account_type": "Capital Work in Progress"}], ["asset_received_but_not_billed", {"account_type": "Asset Received But Not Billed"}], - ["default_inter_company_account", {"root_type": "Liability"}] + ["unrealized_profit_loss_account", {"root_type": "Liability"}] ], function(i, v) { erpnext.company.set_custom_query(frm, v); }); diff --git a/erpnext/setup/doctype/company/company.json b/erpnext/setup/doctype/company/company.json index 4dddff3a05b..d49ae7ce8ac 100644 --- a/erpnext/setup/doctype/company/company.json +++ b/erpnext/setup/doctype/company/company.json @@ -48,7 +48,7 @@ "write_off_account", "exchange_gain_loss_account", "unrealized_exchange_gain_loss_account", - "default_inter_company_account", + "unrealized_profit_loss_account", "column_break0", "allow_account_creation_against_child_company", "default_payable_account", @@ -729,9 +729,9 @@ "options": "Warehouse" }, { - "fieldname": "default_inter_company_account", + "fieldname": "unrealized_profit_loss_account", "fieldtype": "Link", - "label": "Default Inter Company Account", + "label": "Unrealized Profit / Loss Account", "options": "Account" } ], @@ -740,7 +740,7 @@ "image_field": "company_logo", "is_tree": 1, "links": [], - "modified": "2020-11-26 18:20:48.184507", + "modified": "2020-12-03 12:27:27.085094", "modified_by": "Administrator", "module": "Setup", "name": "Company",