refactor(Sales Invoice): set account for mode of payment

(cherry picked from commit 3815f07c33)
This commit is contained in:
barredterra
2024-01-23 13:11:06 +01:00
committed by Mergify
parent 9fd1692db2
commit a072cfbf3f
2 changed files with 7 additions and 17 deletions

View File

@@ -13,7 +13,6 @@ from erpnext.accounts.doctype.loyalty_program.loyalty_program import validate_lo
from erpnext.accounts.doctype.payment_request.payment_request import make_payment_request from erpnext.accounts.doctype.payment_request.payment_request import make_payment_request
from erpnext.accounts.doctype.sales_invoice.sales_invoice import ( from erpnext.accounts.doctype.sales_invoice.sales_invoice import (
SalesInvoice, SalesInvoice,
get_bank_cash_account,
get_mode_of_payment_info, get_mode_of_payment_info,
update_multi_mode_option, update_multi_mode_option,
) )
@@ -52,7 +51,6 @@ class POSInvoice(SalesInvoice):
self.validate_stock_availablility() self.validate_stock_availablility()
self.validate_return_items_qty() self.validate_return_items_qty()
self.set_status() self.set_status()
self.set_account_for_mode_of_payment()
self.validate_pos() self.validate_pos()
self.validate_payment_amount() self.validate_payment_amount()
self.validate_loyalty_transaction() self.validate_loyalty_transaction()
@@ -584,11 +582,6 @@ class POSInvoice(SalesInvoice):
update_multi_mode_option(self, pos_profile) update_multi_mode_option(self, pos_profile)
self.paid_amount = 0 self.paid_amount = 0
def set_account_for_mode_of_payment(self):
for pay in self.payments:
if not pay.account:
pay.account = get_bank_cash_account(pay.mode_of_payment, self.company).get("account")
@frappe.whitelist() @frappe.whitelist()
def create_payment_request(self): def create_payment_request(self):
for pay in self.payments: for pay in self.payments:

View File

@@ -245,7 +245,8 @@ class SalesInvoice(SellingController):
self.calculate_taxes_and_totals() self.calculate_taxes_and_totals()
def before_save(self): def before_save(self):
set_account_for_mode_of_payment(self) self.set_account_for_mode_of_payment()
self.set_paid_amount()
def on_submit(self): def on_submit(self):
self.validate_pos_paid_amount() self.validate_pos_paid_amount()
@@ -538,9 +539,6 @@ class SalesInvoice(SellingController):
): ):
data.sales_invoice = sales_invoice data.sales_invoice = sales_invoice
def on_update(self):
self.set_paid_amount()
def on_update_after_submit(self): def on_update_after_submit(self):
if hasattr(self, "repost_required"): if hasattr(self, "repost_required"):
fields_to_check = [ fields_to_check = [
@@ -571,6 +569,11 @@ class SalesInvoice(SellingController):
self.paid_amount = paid_amount self.paid_amount = paid_amount
self.base_paid_amount = base_paid_amount self.base_paid_amount = base_paid_amount
def set_account_for_mode_of_payment(self):
for payment in self.payments:
if not payment.account:
payment.account = get_bank_cash_account(payment.mode_of_payment, self.company).get("account")
def validate_time_sheets_are_submitted(self): def validate_time_sheets_are_submitted(self):
for data in self.timesheets: for data in self.timesheets:
if data.time_sheet: if data.time_sheet:
@@ -1943,12 +1946,6 @@ def make_sales_return(source_name, target_doc=None):
return make_return_doc("Sales Invoice", source_name, target_doc) return make_return_doc("Sales Invoice", source_name, target_doc)
def set_account_for_mode_of_payment(self):
for data in self.payments:
if not data.account:
data.account = get_bank_cash_account(data.mode_of_payment, self.company).get("account")
def get_inter_company_details(doc, doctype): def get_inter_company_details(doc, doctype):
if doctype in ["Sales Invoice", "Sales Order", "Delivery Note"]: if doctype in ["Sales Invoice", "Sales Order", "Delivery Note"]:
parties = frappe.db.get_all( parties = frappe.db.get_all(