fix: Account naming changes and other fixes

This commit is contained in:
Deepesh Garg
2020-12-04 11:02:05 +05:30
parent e4554f690c
commit 047bf3833e
10 changed files with 46 additions and 30 deletions

View File

@@ -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,

View File

@@ -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",

View File

@@ -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),

View File

@@ -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,

View File

@@ -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",

View File

@@ -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),

View File

@@ -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)

View File

@@ -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()

View File

@@ -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);
});

View File

@@ -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",