From ef71940d586b99729ffa3ac1828863b4801b1867 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Wed, 28 Nov 2012 12:15:45 +0530 Subject: [PATCH 1/3] Update delivered qty and billed amt in SO, if POS against Sales Order --- .../doctype/sales_invoice/sales_invoice.py | 28 ++++++++++++------- selling/doctype/sales_common/sales_common.py | 17 ++++++++++- 2 files changed, 34 insertions(+), 11 deletions(-) diff --git a/accounts/doctype/sales_invoice/sales_invoice.py b/accounts/doctype/sales_invoice/sales_invoice.py index 5dbe20d4f2..3763abb872 100644 --- a/accounts/doctype/sales_invoice/sales_invoice.py +++ b/accounts/doctype/sales_invoice/sales_invoice.py @@ -395,6 +395,11 @@ class DocType(TransactionBase): if not d.item_code: msgprint("Please enter Item Code at line no : %s to update stock for POS or remove check from Update Stock in Basic Info Tab." % (d.idx)) raise Exception + + def validate_delivery_note(self): + for d in self.doclist.get({"parentfield": "entries"}): + if d.delivery_note: + msgprint("""POS can not be made against Delivery Note""", raise_exception=1) def validate_write_off_account(self): @@ -447,6 +452,7 @@ class DocType(TransactionBase): sl.validate_serial_no(self, 'packing_details') self.validate_item_code() self.update_current_stock() + self.validate_delivery_note() self.set_in_words() if not self.doc.is_opening: self.doc.is_opening = 'No' @@ -505,7 +511,9 @@ class DocType(TransactionBase): self.doclist = self.doc.clear_table(self.doclist, 'packing_details') webnotes.conn.set(self.doc,'paid_amount',0) - webnotes.conn.set(self.doc,'outstanding_amount',flt(self.doc.grand_total) - flt(self.doc.total_advance) - flt(self.doc.paid_amount) - flt(self.doc.write_off_amount)) + webnotes.conn.set(self.doc, 'outstanding_amount', + flt(self.doc.grand_total) - flt(self.doc.total_advance) - + flt(self.doc.paid_amount) - flt(self.doc.write_off_amount)) def check_prev_docstatus(self): @@ -533,7 +541,7 @@ class DocType(TransactionBase): 'posting_time' : self.doc.posting_time, 'voucher_type' : 'Sales Invoice', 'voucher_no' : cstr(self.doc.name), - 'voucher_detail_no' : cstr(d['name']), + 'voucher_detail_no' : cstr(d['name']), 'actual_qty' : qty, 'stock_uom' : st_uom and st_uom[0][0] or '', 'incoming_rate' : in_value, @@ -604,13 +612,13 @@ class DocType(TransactionBase): self.update_stock_ledger(update_stock=1) else: - self.check_prev_docstatus() - get_obj("Sales Common").update_prevdoc_detail(1,self) - # Check for Approving Authority if not self.doc.recurring_id: get_obj('Authorization Control').validate_approving_authority(self.doc.doctype, self.doc.company, self.doc.grand_total, self) + self.check_prev_docstatus() + get_obj("Sales Common").update_prevdoc_detail(1,self) + # this sequence because outstanding may get -ve self.make_gl_entries() @@ -628,11 +636,11 @@ class DocType(TransactionBase): sl.update_serial_record(self, 'packing_details', is_submit = 0, is_incoming = 0) self.update_stock_ledger(update_stock = -1) - else: - sales_com_obj = get_obj(dt = 'Sales Common') - sales_com_obj.check_stop_sales_order(self) - self.check_next_docstatus() - sales_com_obj.update_prevdoc_detail(0,self) + + sales_com_obj = get_obj(dt = 'Sales Common') + sales_com_obj.check_stop_sales_order(self) + self.check_next_docstatus() + sales_com_obj.update_prevdoc_detail(0, self) self.make_gl_entries(is_cancel=1) diff --git a/selling/doctype/sales_common/sales_common.py b/selling/doctype/sales_common/sales_common.py index 2a8182d9f2..8ea4fe40fc 100644 --- a/selling/doctype/sales_common/sales_common.py +++ b/selling/doctype/sales_common/sales_common.py @@ -829,7 +829,22 @@ class StatusUpdater: 'status_field' :'billing_status', 'keyword' :'Billed' }) - + + if cint(self.obj.doc.is_pos) == 1: + self.update_qty({ + 'target_field' :'delivered_qty', + 'target_dt' :'Sales Order Item', + 'target_parent_dt' :'Sales Order', + 'target_parent_field' :'per_delivered', + 'target_ref_field' :'qty', + 'source_dt' :'Sales Invoice Item', + 'source_field' :'qty', + 'join_field' :'so_detail', + 'percent_join_field' :'sales_order', + 'status_field' :'delivery_status', + 'keyword' :'Delivered' + }) + if self.obj.doc.doctype=='Installation Note': self.update_qty({ 'target_field' :'installed_qty', From d9eb526b27c3d5037a6b2162328b1d8692f5b81c Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Wed, 28 Nov 2012 12:40:52 +0530 Subject: [PATCH 2/3] patch: update % delievered and % billed in SO if pos made against that so --- .../update_delivered_billed_percentage_for_pos.py | 15 +++++++++++++++ patches/patch_list.py | 4 ++++ 2 files changed, 19 insertions(+) create mode 100644 patches/november_2012/update_delivered_billed_percentage_for_pos.py diff --git a/patches/november_2012/update_delivered_billed_percentage_for_pos.py b/patches/november_2012/update_delivered_billed_percentage_for_pos.py new file mode 100644 index 0000000000..3e9adf416a --- /dev/null +++ b/patches/november_2012/update_delivered_billed_percentage_for_pos.py @@ -0,0 +1,15 @@ +def execute(): + import webnotes + from webnotes.model.code import get_obj + + sc_obj = get_obj("Sales Common") + + si = webnotes.conn.sql("""select si.name + from `tabSales Invoice` si, `tabSales Invoice Item` si_item + where si_item.parent = si.name + and si.docstatus = 1 + and ifnull(si.is_pos, 0) = 1 + and ifnull(si_item.sales_order, '') != '' + """) + for d in si: + sc_obj.update_prevdoc_detail(1, get_obj("Sales Invoice", d[0], with_children=1)) \ No newline at end of file diff --git a/patches/patch_list.py b/patches/patch_list.py index 5cacfb239b..55a8bb4d8d 100644 --- a/patches/patch_list.py +++ b/patches/patch_list.py @@ -691,4 +691,8 @@ patch_list = [ 'patch_module': 'patches.november_2012', 'patch_file': 'communication_sender_and_recipient', }, + { + 'patch_module': 'patches.november_2012', + 'patch_file': 'update_delivered_billed_percentage_for_pos', + }, ] \ No newline at end of file From dcc4ff5ca3426d64bba2b17b1add57ed4eb2ba2a Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Wed, 28 Nov 2012 14:12:49 +0530 Subject: [PATCH 3/3] patch: update % delievered and % billed in SO if pos made against that so --- .../november_2012/update_delivered_billed_percentage_for_pos.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/patches/november_2012/update_delivered_billed_percentage_for_pos.py b/patches/november_2012/update_delivered_billed_percentage_for_pos.py index 3e9adf416a..502a36a748 100644 --- a/patches/november_2012/update_delivered_billed_percentage_for_pos.py +++ b/patches/november_2012/update_delivered_billed_percentage_for_pos.py @@ -4,7 +4,7 @@ def execute(): sc_obj = get_obj("Sales Common") - si = webnotes.conn.sql("""select si.name + si = webnotes.conn.sql("""select distinct si.name from `tabSales Invoice` si, `tabSales Invoice Item` si_item where si_item.parent = si.name and si.docstatus = 1