diff --git a/erpnext/accounts/doctype/purchase_invoice/services/gl_composer.py b/erpnext/accounts/doctype/purchase_invoice/services/gl_composer.py index d295814ff9a..786cfd61273 100644 --- a/erpnext/accounts/doctype/purchase_invoice/services/gl_composer.py +++ b/erpnext/accounts/doctype/purchase_invoice/services/gl_composer.py @@ -32,7 +32,7 @@ class PurchaseInvoiceGLComposer(BaseGLComposer): self.make_supplier_gl_entry(gl_entries) self.make_item_gl_entries(gl_entries) - doc.make_precision_loss_gl_entry(gl_entries) + self.make_precision_loss_gl_entry(gl_entries) self.make_tax_gl_entries(gl_entries) self.make_internal_transfer_gl_entries(gl_entries) @@ -48,6 +48,35 @@ class PurchaseInvoiceGLComposer(BaseGLComposer): doc.set_gl_entry_for_purchase_expense(gl_entries) return gl_entries + def make_precision_loss_gl_entry(self, gl_entries): + doc = self.doc + ( + round_off_account, + round_off_cost_center, + _round_off_for_opening, + ) = get_round_off_account_and_cost_center( + doc.company, "Purchase Invoice", doc.name, doc.use_company_roundoff_cost_center + ) + + precision_loss = doc.get("base_net_total") - flt( + doc.get("net_total") * doc.conversion_rate, doc.precision("net_total") + ) + + if precision_loss: + gl_entries.append( + doc.get_gl_dict( + { + "account": round_off_account, + "against": doc.supplier, + "credit": precision_loss, + "cost_center": round_off_cost_center + if doc.use_company_roundoff_cost_center + else doc.cost_center or round_off_cost_center, + "remarks": _("Net total calculation precision loss"), + } + ) + ) + def make_supplier_gl_entry(self, gl_entries): doc = self.doc grand_total = ( diff --git a/erpnext/accounts/doctype/sales_invoice/services/gl_composer.py b/erpnext/accounts/doctype/sales_invoice/services/gl_composer.py index afde7472717..8eb1b82a4ae 100644 --- a/erpnext/accounts/doctype/sales_invoice/services/gl_composer.py +++ b/erpnext/accounts/doctype/sales_invoice/services/gl_composer.py @@ -39,7 +39,7 @@ class SalesInvoiceGLComposer(BaseGLComposer): if not (doc.is_return and disable_sdbnb_in_sr): self.stock_delivered_but_not_billed_gl_entries(gl_entries) - doc.make_precision_loss_gl_entry(gl_entries) + self.make_precision_loss_gl_entry(gl_entries) tax_service.make_discount_gl_entries(gl_entries) gl_entries = make_regional_gl_entries(gl_entries, doc) @@ -56,6 +56,35 @@ class SalesInvoiceGLComposer(BaseGLComposer): doc.set_transaction_currency_and_rate_in_gl_map(gl_entries) return gl_entries + def make_precision_loss_gl_entry(self, gl_entries): + doc = self.doc + ( + round_off_account, + round_off_cost_center, + _round_off_for_opening, + ) = get_round_off_account_and_cost_center( + doc.company, "Sales Invoice", doc.name, doc.use_company_roundoff_cost_center + ) + + precision_loss = doc.get("base_net_total") - flt( + doc.get("net_total") * doc.conversion_rate, doc.precision("net_total") + ) + + if precision_loss: + gl_entries.append( + doc.get_gl_dict( + { + "account": round_off_account, + "against": doc.customer, + "debit": precision_loss, + "cost_center": round_off_cost_center + if doc.use_company_roundoff_cost_center + else doc.cost_center or round_off_cost_center, + "remarks": _("Net total calculation precision loss"), + } + ) + ) + def stock_delivered_but_not_billed_gl_entries(self, gl_entries): doc = self.doc if doc.update_stock or not cint(erpnext.is_perpetual_inventory_enabled(doc.company)): diff --git a/erpnext/accounts/services/exchange_gain_loss.py b/erpnext/accounts/services/exchange_gain_loss.py index b7ed77bc664..fa3af053a18 100644 --- a/erpnext/accounts/services/exchange_gain_loss.py +++ b/erpnext/accounts/services/exchange_gain_loss.py @@ -8,38 +8,9 @@ from frappe import _, qb from frappe.utils import flt, get_link_to_form from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import get_dimensions -from erpnext.accounts.general_ledger import get_round_off_account_and_cost_center from erpnext.accounts.utils import create_gain_loss_journal, get_currency_precision -def make_precision_loss_gl_entry(doc, gl_entries: list) -> None: - round_off_account, round_off_cost_center, _ = get_round_off_account_and_cost_center( - doc.company, "Purchase Invoice", doc.name, doc.use_company_roundoff_cost_center - ) - - precision_loss = doc.get("base_net_total") - flt( - doc.get("net_total") * doc.conversion_rate, doc.precision("net_total") - ) - - credit_or_debit = "credit" if doc.doctype == "Purchase Invoice" else "debit" - against = doc.supplier if doc.doctype == "Purchase Invoice" else doc.customer - - if precision_loss: - gl_entries.append( - doc.get_gl_dict( - { - "account": round_off_account, - "against": against, - credit_or_debit: precision_loss, - "cost_center": round_off_cost_center - if doc.use_company_roundoff_cost_center - else doc.cost_center or round_off_cost_center, - "remarks": _("Net total calculation precision loss"), - } - ) - ) - - def gain_loss_journal_already_booked( gain_loss_account: str, exc_gain_loss: float, diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index 563d9f516dd..7ed819167ea 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -1043,11 +1043,6 @@ class AccountsController(TransactionBase): set_advance_gain_or_loss(self) - def make_precision_loss_gl_entry(self, gl_entries): - from erpnext.accounts.services.exchange_gain_loss import make_precision_loss_gl_entry - - make_precision_loss_gl_entry(self, gl_entries) - def gain_loss_journal_already_booked( self, gain_loss_account, exc_gain_loss, ref2_dt, ref2_dn, ref2_detail_no ) -> bool: