[validation] over billing against DN/PR
This commit is contained in:
parent
170f3fa575
commit
3b999225ba
@ -75,6 +75,7 @@ class DocType(BuyingController):
|
||||
self.validate_write_off_account()
|
||||
self.update_raw_material_cost()
|
||||
self.update_valuation_rate("entries")
|
||||
self.validate_multiple_billing("Purchase Receipt", "pr_detail", "import_amount")
|
||||
|
||||
def get_credit_to(self):
|
||||
acc_head = sql("""select name, credit_days from `tabAccount`
|
||||
|
@ -93,6 +93,7 @@ class DocType(SellingController):
|
||||
self.validate_c_form()
|
||||
self.validate_time_logs_are_submitted()
|
||||
self.validate_recurring_invoice()
|
||||
self.validate_multiple_billing("Delivered Note", "dn_detail", "export_amount")
|
||||
|
||||
def on_submit(self):
|
||||
if cint(self.doc.update_stock) == 1:
|
||||
|
@ -354,6 +354,22 @@ class AccountsController(TransactionBase):
|
||||
"advance_amount": flt(d.amount),
|
||||
"allocate_amount": 0
|
||||
})
|
||||
|
||||
def validate_multiple_billing(self, ref_dt, item_ref_dn, based_on):
|
||||
for item in self.doclist.get({"parentfield": "entries"}):
|
||||
if item.fields.get(item_ref_dn):
|
||||
already_billed = webnotes.conn.sql("""select sum(%s) from `tab%s`
|
||||
where %s=%s and docstatus=1""" % (based_on, self.tname, item_ref_dn, '%s'),
|
||||
item.fields[item_ref_dn])[0][0]
|
||||
if already_billed:
|
||||
max_allowed_amt = webnotes.conn.get_value(ref_dt + " Item",
|
||||
item.fields[item_ref_dn], based_on)
|
||||
|
||||
if flt(already_billed) + flt(item.fields[based_on]) > max_allowed_amt:
|
||||
webnotes.msgprint(_("Row ")+ item.idx + ": " + item.item_code +
|
||||
_(" will be over-billed against mentioned ") + ref_dt +
|
||||
_(". Max allowed " + based_on + ": " + max_allowed_amt),
|
||||
raise_exception=1)
|
||||
|
||||
def get_company_default(self, fieldname):
|
||||
from accounts.utils import get_company_default
|
||||
|
@ -28,6 +28,25 @@ class TestDeliveryNote(unittest.TestCase):
|
||||
pr.run_method("calculate_taxes_and_totals")
|
||||
pr.insert()
|
||||
pr.submit()
|
||||
|
||||
def test_over_billing_against_dn(self):
|
||||
from stock.doctype.delivery_note.delivery_note import make_sales_invoice
|
||||
|
||||
dn = webnotes.bean(copy=test_records[0]).insert()
|
||||
|
||||
self.assertRaises(webnotes.ValidationError, make_sales_invoice,
|
||||
dn.doc.name)
|
||||
|
||||
dn = webnotes.bean("Delivery Note", dn.doc.name)
|
||||
dn.submit()
|
||||
si = make_sales_invoice(dn.doc.name)
|
||||
|
||||
self.assertEquals(len(si), len(dn.doclist))
|
||||
|
||||
# modify export_amount
|
||||
si[1].export_rate = 200
|
||||
self.assertRaises(webnotes.ValidationError, webnotes.bean(si).submit)
|
||||
|
||||
|
||||
def test_delivery_note_no_gl_entry(self):
|
||||
webnotes.conn.sql("""delete from `tabBin`""")
|
||||
|
@ -22,7 +22,7 @@ import webnotes.defaults
|
||||
from webnotes.utils import cint
|
||||
|
||||
class TestPurchaseReceipt(unittest.TestCase):
|
||||
def test_make_purchase_invocie(self):
|
||||
def test_make_purchase_invoice(self):
|
||||
from stock.doctype.purchase_receipt.purchase_receipt import make_purchase_invoice
|
||||
|
||||
pr = webnotes.bean(copy=test_records[0]).insert()
|
||||
@ -37,6 +37,10 @@ class TestPurchaseReceipt(unittest.TestCase):
|
||||
self.assertEquals(pi[0]["doctype"], "Purchase Invoice")
|
||||
self.assertEquals(len(pi), len(pr.doclist))
|
||||
|
||||
# modify import_rate
|
||||
pi[1].import_rate = 200
|
||||
self.assertRaises(webnotes.ValidationError, webnotes.bean(pi).submit)
|
||||
|
||||
def test_purchase_receipt_no_gl_entry(self):
|
||||
pr = webnotes.bean(copy=test_records[0])
|
||||
pr.run_method("calculate_taxes_and_totals")
|
||||
|
Loading…
x
Reference in New Issue
Block a user