sales_invoice.py -- Check credit limit when make delivery is done from sales invoice.We need to check the credit limit as there could be multiple partially paid sales order(note we are bypassing credit check at sales order) so we need to recheck credit balance of customer to avoid any delivery crossing credit limit from sales invoice

This commit is contained in:
ashish 2017-10-25 16:11:58 +05:30
parent 8ad4efee25
commit ff20182d03

View File

@ -70,7 +70,6 @@ class SalesInvoice(SellingController):
self.clear_unallocated_advances("Sales Invoice Advance", "advances") self.clear_unallocated_advances("Sales Invoice Advance", "advances")
self.add_remarks() self.add_remarks()
self.validate_write_off_account() self.validate_write_off_account()
self.validate_duplicate_offline_pos_entry()
self.validate_account_for_change_amount() self.validate_account_for_change_amount()
self.validate_fixed_asset() self.validate_fixed_asset()
self.set_income_account_for_fixed_assets() self.set_income_account_for_fixed_assets()
@ -463,12 +462,6 @@ class SalesInvoice(SellingController):
if flt(self.write_off_amount) and not self.write_off_account: if flt(self.write_off_amount) and not self.write_off_account:
msgprint(_("Please enter Write Off Account"), raise_exception=1) msgprint(_("Please enter Write Off Account"), raise_exception=1)
def validate_duplicate_offline_pos_entry(self):
if self.is_pos and self.offline_pos_name \
and frappe.db.get_value('Sales Invoice',
{'offline_pos_name': self.offline_pos_name, 'docstatus': 1}):
frappe.throw(_("Duplicate offline pos sales invoice {0}").format(self.offline_pos_name))
def validate_account_for_change_amount(self): def validate_account_for_change_amount(self):
if flt(self.change_amount) and not self.account_for_change_amount: if flt(self.change_amount) and not self.account_for_change_amount:
msgprint(_("Please enter Account for Change Amount"), raise_exception=1) msgprint(_("Please enter Account for Change Amount"), raise_exception=1)
@ -924,6 +917,13 @@ def make_delivery_note(source_name, target_doc=None):
target.run_method("set_missing_values") target.run_method("set_missing_values")
target.run_method("calculate_taxes_and_totals") target.run_method("calculate_taxes_and_totals")
#PR : 10861, Author : ashish-greycube & jigneshpshah, Email:mr.ashish.shah@gmail.com
# Since the credit limit check is bypassed at sales order level, we need to check it at delivery note
bypass_credit_limit_check_at_sales_order = frappe.db.get_value("Customer", source.customer, "bypass_credit_limit_check_at_sales_order")
if bypass_credit_limit_check_at_sales_order == 1:
from erpnext.selling.doctype.customer.customer import check_credit_limit
check_credit_limit(source.customer, source.company)
def update_item(source_doc, target_doc, source_parent): def update_item(source_doc, target_doc, source_parent):
target_doc.qty = flt(source_doc.qty) - flt(source_doc.delivered_qty) target_doc.qty = flt(source_doc.qty) - flt(source_doc.delivered_qty)
target_doc.stock_qty = target_doc.qty * flt(source_doc.conversion_factor) target_doc.stock_qty = target_doc.qty * flt(source_doc.conversion_factor)