[sales invoice] [fetching] fetch customer info, pos settings and item details if not fetched
This commit is contained in:
parent
855cf8db21
commit
d2b8b83e20
@ -45,15 +45,7 @@ class DocType(SellingController):
|
||||
|
||||
def validate(self):
|
||||
super(DocType, self).validate()
|
||||
|
||||
if not (self.doc.contact_person and self.doc.customer_address):
|
||||
for fieldname, val in self.get_default_address_and_contact("customer").items():
|
||||
if not self.doc.fields.get(fieldname) and self.meta.get_field(fieldname):
|
||||
self.doc.fields[fieldname] = val
|
||||
|
||||
if cint(self.doc.is_pos):
|
||||
self.set_pos_fields(for_validate=True)
|
||||
|
||||
self.fetch_missing_values()
|
||||
self.validate_posting_time()
|
||||
self.so_dn_required()
|
||||
self.validate_proj_cust()
|
||||
@ -146,6 +138,26 @@ class DocType(SellingController):
|
||||
self.validate_recurring_invoice()
|
||||
self.convert_to_recurring()
|
||||
|
||||
def fetch_missing_values(self):
|
||||
# fetch contact and address details for customer, if they are not mentioned
|
||||
if not (self.doc.contact_person and self.doc.customer_address):
|
||||
for fieldname, val in self.get_default_address_and_contact("customer").items():
|
||||
if not self.doc.fields.get(fieldname) and self.meta.get_field(fieldname):
|
||||
self.doc.fields[fieldname] = val
|
||||
|
||||
# fetch missing item values
|
||||
for item in self.doclist.get({"parentfield": "entries"}):
|
||||
if item.fields.get("item_code"):
|
||||
ret = get_obj('Sales Common').get_item_details(item.fields, self)
|
||||
for fieldname, value in ret.items():
|
||||
if self.meta.get_field(fieldname, parentfield="entries") and \
|
||||
not item.fields.get(fieldname):
|
||||
item.fields[fieldname] = value
|
||||
|
||||
# fetch pos details, if they are not fetched
|
||||
if cint(self.doc.is_pos):
|
||||
self.set_pos_fields(for_validate=True)
|
||||
|
||||
def update_time_log_batch(self, sales_invoice):
|
||||
for d in self.doclist.get({"doctype":"Sales Invoice Item"}):
|
||||
if d.time_log_batch:
|
||||
@ -294,6 +306,7 @@ class DocType(SellingController):
|
||||
ret = self.apply_pos_settings(args, ret)
|
||||
|
||||
return ret
|
||||
|
||||
elif cint(self.doc.is_pos) == 1 and self.pos_settings:
|
||||
for doc in self.doclist.get({"parentfield": "entries"}):
|
||||
if doc.fields.get('item_code'):
|
||||
|
@ -90,6 +90,9 @@ class TestSalesInvoice(unittest.TestCase):
|
||||
webnotes.conn.sql("delete from `tabStock Ledger Entry`")
|
||||
webnotes.defaults.set_global_default("auto_inventory_accounting", 1)
|
||||
|
||||
old_default_company = webnotes.conn.get_default("company")
|
||||
webnotes.conn.set_default("company", "_Test Company")
|
||||
|
||||
self._insert_purchase_receipt()
|
||||
self._insert_pos_settings()
|
||||
|
||||
@ -106,7 +109,8 @@ class TestSalesInvoice(unittest.TestCase):
|
||||
|
||||
# check stock ledger entries
|
||||
sle = webnotes.conn.sql("""select * from `tabStock Ledger Entry`
|
||||
where voucher_type = 'Sales Invoice' and voucher_no = %s""", si.doc.name, as_dict=1)[0]
|
||||
where voucher_type = 'Sales Invoice' and voucher_no = %s""",
|
||||
si.doc.name, as_dict=1)[0]
|
||||
self.assertTrue(sle)
|
||||
self.assertEquals([sle.item_code, sle.warehouse, sle.actual_qty],
|
||||
["_Test Item", "_Test Warehouse", -5.0])
|
||||
@ -145,6 +149,7 @@ class TestSalesInvoice(unittest.TestCase):
|
||||
self.assertEquals(gl_count[0][0], 16)
|
||||
|
||||
webnotes.defaults.set_global_default("auto_inventory_accounting", 0)
|
||||
webnotes.conn.set_default("company", old_default_company)
|
||||
|
||||
def test_sales_invoice_gl_entry_with_aii_no_item_code(self):
|
||||
webnotes.defaults.set_global_default("auto_inventory_accounting", 1)
|
||||
@ -337,7 +342,7 @@ class TestSalesInvoice(unittest.TestCase):
|
||||
# change posting date but keep recuring day to be today
|
||||
si7 = webnotes.bean(copy=base_si.doclist)
|
||||
si7.doc.fields.update({
|
||||
"posting_date": add_to_date(today, days=-3)
|
||||
"posting_date": add_to_date(today, days=-1)
|
||||
})
|
||||
si7.insert()
|
||||
si7.submit()
|
||||
@ -361,7 +366,8 @@ class TestSalesInvoice(unittest.TestCase):
|
||||
manage_recurring_invoices(next_date=next_date, commit=False)
|
||||
|
||||
recurred_invoices = webnotes.conn.sql("""select name from `tabSales Invoice`
|
||||
where recurring_id=%s and docstatus=1 order by name desc""", base_si.doc.recurring_id)
|
||||
where recurring_id=%s and docstatus=1 order by name desc""",
|
||||
base_si.doc.recurring_id)
|
||||
|
||||
self.assertEquals(i+2, len(recurred_invoices))
|
||||
|
||||
|
@ -21,6 +21,7 @@ import webnotes.defaults
|
||||
from webnotes.utils import cint
|
||||
|
||||
keydict = {
|
||||
# "key in defaults": "key in Global Defaults"
|
||||
"print_style": "print_style",
|
||||
"fiscal_year": "current_fiscal_year",
|
||||
'company': 'default_company',
|
||||
|
Loading…
x
Reference in New Issue
Block a user