serialized inventory fixes : serial no for sales bom child item and rejected qty

This commit is contained in:
Nabin Hait 2012-05-09 15:26:27 +05:30
parent a6b8e84f09
commit 68f9ad31ae
10 changed files with 129 additions and 150 deletions

View File

@ -119,7 +119,6 @@ cur_frm.cscript.refresh = function(doc, dt, dn) {
// Show / Hide button
cur_frm.clear_custom_buttons();
if (!cur_frm.cscript.is_onload) cur_frm.cscript.hide_price_list_currency(doc, dt, dn);
if(doc.docstatus==1) {

View File

@ -138,7 +138,7 @@ class DocType(TransactionBase):
if d.serial_no:
sr_list = get_sr_no_list(d.serial_no, d.qty)
sr_list = get_sr_no_list(d.serial_no, d.qty, d.item_code)
self.is_serial_no_exist(d.item_code, sr_list)
prevdoc_s_no = self.get_prevdoc_serial_no(d.prevdoc_detail_docname, d.prevdoc_docname)

View File

@ -311,16 +311,6 @@ class DocType(TransactionBase):
}
return ret
# Make Packing List from Sales BOM
# =======================================================================
def has_sales_bom(self, item_code):
return webnotes.conn.sql("select name from `tabSales BOM` where name=%s and docstatus != 2", item_code)
def get_sales_bom_items(self, item_code):
return webnotes.conn.sql("select item_code, qty, uom from `tabSales BOM Item` where parent=%s", item_code)
# --------------
# get item list
# --------------
@ -345,8 +335,9 @@ class DocType(TransactionBase):
warehouse = (obj.fname == "sales_order_details") and d.reserved_warehouse or d.warehouse
if self.has_sales_bom(d.item_code):
for i in self.get_sales_bom_items(d.item_code):
il.append([warehouse, i[0], flt(flt(i[1])* qty), flt(flt(i[1])*reserved_qty), i[2], d.batch_no, d.serial_no])
for p in getlist(obj.doclist, 'packing_details'):
if p.parent_item == d.item_code:
il.append([warehouse, p.item_code, flt(p.qty)*qty, flt(p.qty)* reserved_qty, p.uom, p.batch_no, p.serial_no])
else:
il.append([warehouse, d.item_code, qty, reserved_qty, d.stock_uom, d.batch_no, d.serial_no])
return il
@ -371,12 +362,16 @@ class DocType(TransactionBase):
return qty, max_qty, amt, max_amt
# Make Packing List from Sales BOM
# =======================================================================
def has_sales_bom(self, item_code):
return webnotes.conn.sql("select name from `tabSales BOM` where new_item_code=%s and docstatus != 2", item_code)
def get_sales_bom_items(self, item_code):
return webnotes.conn.sql("""select t1.item_code, t1.qty, t1.uom
from `tabSales BOM Item` t1, `tabSales BOM` t2
where t2.new_item_code=%s and t1.parent = t2.name""", item_code, as_dict=1)
# -----------------------
# add packing list items
# -----------------------
def get_packing_item_details(self, item):
return webnotes.conn.sql("select item_name, description, stock_uom from `tabItem` where name = %s", item, as_dict = 1)[0]
@ -384,12 +379,22 @@ class DocType(TransactionBase):
det = webnotes.conn.sql("select actual_qty, projected_qty from `tabBin` where item_code = '%s' and warehouse = '%s'" % (item, warehouse), as_dict = 1)
return det and det[0] or ''
def add_packing_list_item(self,obj, item_code, qty, warehouse, line):
bin = self.get_bin_qty(item_code, warehouse)
item = self.get_packing_item_details(item_code)
pi = addchild(obj.doc, 'packing_details', 'Delivery Note Packing Item', 1, obj.doclist)
pi.parent_item = item_code
pi.item_code = item_code
def update_packing_list_item(self,obj, packing_item_code, qty, warehouse, line):
bin = self.get_bin_qty(packing_item_code, warehouse)
item = self.get_packing_item_details(packing_item_code)
# check if exists
exists = 0
for d in getlist(obj.doclist, 'packing_details'):
if d.parent_item == line.item_code and d.item_code == packing_item_code:
pi, exists = d, 1
break
if not exists:
pi = addchild(obj.doc, 'packing_details', 'Delivery Note Packing Item', 1, obj.doclist)
pi.parent_item = line.item_code
pi.item_code = packing_item_code
pi.item_name = item['item_name']
pi.parent_detail_docname = line.name
pi.description = item['description']
@ -399,7 +404,9 @@ class DocType(TransactionBase):
pi.projected_qty = bin and flt(bin['projected_qty']) or 0
pi.warehouse = warehouse
pi.prevdoc_doctype = line.prevdoc_doctype
pi.serial_no = cstr(line.serial_no)
if packing_item_code == line.item_code:
pi.serial_no = cstr(line.serial_no)
pi.batch_no = cstr(line.batch_no)
pi.idx = self.packing_list_idx
self.packing_list_idx += 1
@ -408,15 +415,14 @@ class DocType(TransactionBase):
# make packing list from sales bom if exists or directly copy item with balance
# ------------------
def make_packing_list(self, obj, fname):
obj.doc.clear_table(obj.doclist, 'packing_details')
self.packing_list_idx = 0
for d in getlist(obj.doclist, fname):
warehouse = fname == "sales_order_details" and d.reserved_warehouse or d.warehouse
if self.has_sales_bom(d.item_code):
for i in self.get_sales_bom_items(d.item_code):
self.add_packing_list_item(obj, i[0], flt(i[1])*flt(d.qty), warehouse, d)
self.update_packing_list_item(obj, i['item_code'], flt(i['qty'])*flt(d.qty), warehouse, d)
else:
self.add_packing_list_item(obj, d.item_code, d.qty, warehouse, d)
self.update_packing_list_item(obj, d.item_code, d.qty, warehouse, d)
# Get total in words

View File

@ -416,7 +416,6 @@ class DocType(TransactionBase):
if not d[0]:
msgprint("Message: Please enter Warehouse for item %s as it is stock item."% d[1])
raise Exception
# if prevdoc_doctype = "Sales Order"
if d[3] < 0 :
# Reduce Reserved Qty from warehouse
bin = get_obj('Warehouse', d[0]).update_bin(0, flt(update_stock) * flt(d[3]), 0, 0, 0, d[1], self.doc.transaction_date,doc_type=self.doc.doctype,doc_name=self.doc.name, is_amended = (self.doc.amended_from and 'Yes' or 'No'))

View File

@ -3,9 +3,9 @@
# These values are common in all dictionaries
{
'creation': '2012-03-27 14:36:30',
'creation': '2012-04-13 11:56:35',
'docstatus': 0,
'modified': '2012-03-27 14:36:30',
'modified': '2012-05-09 12:55:23',
'modified_by': u'Administrator',
'owner': u'Administrator'
},
@ -20,7 +20,7 @@
'section_style': u'Tray',
'server_code_error': u' ',
'show_in_menu': 0,
'version': 17
'version': 1
},
# These values are common for all DocField
@ -134,6 +134,15 @@
'permlevel': 0
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'batch_no',
'fieldtype': u'Data',
'label': u'Batch No',
'permlevel': 0
},
# DocField
{
'doctype': u'DocField',
@ -171,34 +180,6 @@
'search_index': 0
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'planned_qty',
'fieldtype': u'Currency',
'hidden': 1,
'label': u'Planned Qty ',
'no_copy': 1,
'oldfieldname': u'planned_qty',
'oldfieldtype': u'Currency',
'permlevel': 1,
'print_hide': 1
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'produced_qty',
'fieldtype': u'Currency',
'hidden': 1,
'label': u'Produced Qty',
'no_copy': 1,
'oldfieldname': u'produced_qty',
'oldfieldtype': u'Currency',
'permlevel': 1,
'print_hide': 1
},
# DocField
{
'colour': u'White:FFF',
@ -213,47 +194,6 @@
'print_hide': 1
},
# DocField
{
'description': u'The date at which current entry is made in system.',
'doctype': u'DocField',
'fieldname': u'transaction_date',
'fieldtype': u'Date',
'hidden': 0,
'label': u'Sales Order Date',
'oldfieldname': u'transaction_date',
'oldfieldtype': u'Date',
'permlevel': 1,
'print_hide': 1
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'delivery_date',
'fieldtype': u'Date',
'hidden': 0,
'label': u'Expected Delivery Date',
'oldfieldname': u'delivery_date',
'oldfieldtype': u'Date',
'permlevel': 1,
'print_hide': 1
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'confirmation_date',
'fieldtype': u'Date',
'hidden': 1,
'label': u'Confirmed delivery date',
'no_copy': 1,
'oldfieldname': u'confirmation_date',
'oldfieldtype': u'Date',
'permlevel': 1,
'print_hide': 1
},
# DocField
{
'allow_on_submit': 1,

View File

@ -114,7 +114,7 @@ class DocType(TransactionBase):
# If Reject Qty than Rejected warehouse is mandatory
if flt(d.rejected_qty) and (not self.doc.rejected_warehouse):
msgprint("Rejected Warehouse is necessary if there are rejections. See 'Receipt Items'")
msgprint("Rejected Warehouse is necessary if there are rejections.")
raise Exception
# Check Received Qty = Accepted Qty + Rejected Qty
@ -198,6 +198,15 @@ class DocType(TransactionBase):
self.update_rw_material_detail()
get_obj('Stock Ledger').scrub_serial_nos(self)
self.scrub_rejected_serial_nos()
def scrub_rejected_serial_nos(self):
for d in getlist(self.doclist, 'purchase_receipt_details'):
if d.rejected_serial_no:
d.rejected_serial_no = d.rejected_serial_no.replace(',', '\n')
d.save()
# On Submit
@ -232,7 +241,7 @@ class DocType(TransactionBase):
self.make_sl_entry(d, d.warehouse, flt(pr_qty), d.valuation_rate, is_submit)
# UPDATE actual to rejected warehouse by rejected qty
if flt(d.rejected_qty) > 0:
self.make_sl_entry(d, self.doc.rejected_warehouse, flt(d.rejected_qty) * flt(d.conversion_factor), d.valuation_rate, is_submit)
self.make_sl_entry(d, self.doc.rejected_warehouse, flt(d.rejected_qty) * flt(d.conversion_factor), d.valuation_rate, is_submit, rejected = 1)
self.bk_flush_supp_wh(is_submit)
@ -241,24 +250,29 @@ class DocType(TransactionBase):
# make Stock Entry
def make_sl_entry(self, d, wh, qty, in_value, is_submit):
def make_sl_entry(self, d, wh, qty, in_value, is_submit, rejected = 0):
if rejected:
serial_no = d.rejected_serial_no
else:
serial_no = d.serial_no
self.values.append({
'item_code' : d.fields.has_key('item_code') and d.item_code or d.rm_item_code,
'warehouse' : wh,
'item_code' : d.fields.has_key('item_code') and d.item_code or d.rm_item_code,
'warehouse' : wh,
'transaction_date' : getdate(self.doc.modified).strftime('%Y-%m-%d'),
'posting_date' : self.doc.posting_date,
'posting_time' : self.doc.posting_time,
'voucher_type' : 'Purchase Receipt',
'voucher_no' : self.doc.name,
'voucher_detail_no' : d.name,
'actual_qty' : qty,
'stock_uom' : d.stock_uom,
'incoming_rate' : in_value,
'company' : self.doc.company,
'fiscal_year' : self.doc.fiscal_year,
'voucher_no' : self.doc.name,
'voucher_detail_no' : d.name,
'actual_qty' : qty,
'stock_uom' : d.stock_uom,
'incoming_rate' : in_value,
'company' : self.doc.company,
'fiscal_year' : self.doc.fiscal_year,
'is_cancelled' : (is_submit==1) and 'No' or 'Yes',
'batch_no' : d.batch_no,
'serial_no' : d.serial_no
'batch_no' : d.batch_no,
'serial_no' : serial_no
})

View File

@ -3,9 +3,9 @@
# These values are common in all dictionaries
{
'creation': '2012-03-27 14:36:35',
'creation': '2012-04-13 11:56:36',
'docstatus': 0,
'modified': '2012-03-27 14:36:35',
'modified': '2012-05-09 14:25:12',
'modified_by': u'Administrator',
'owner': u'Administrator'
},
@ -22,7 +22,7 @@
'section_style': u'Tray',
'server_code_error': u' ',
'show_in_menu': 0,
'version': 78
'version': 1
},
# These values are common for all DocField
@ -299,6 +299,16 @@
'report_hide': 0
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'rejected_serial_no',
'fieldtype': u'Text',
'label': u'Rejected Serial No',
'permlevel': 0,
'print_hide': 1
},
# DocField
{
'colour': u'White:FFF',

View File

@ -23,7 +23,7 @@ cur_frm.cscript.onload = function(doc, cdt, cdn) {
cur_frm.cscript.refresh = function(doc, cdt, cdn) {
if(!doc.__islocal) {
hide_field('new_item_code');
get_field(doc.doctype, 'new_item_code', doc.name).permlevel = 1;
}
}

View File

@ -62,13 +62,9 @@ class DocType:
if d.is_main_item == 'Yes':
is_main_item.append(d.item_code)
# Check that Sales Bom Item cannot be child of Sales Bom.
if sql("select name from `tabSales BOM` where name = '%s' " % d.item_code):
msgprint("Sales Bom Item " + d.item_code +" cannot be child item.")
if d.item_code == self.doc.new_item_code:
msgprint("Sales Bom Item " + d.new_item_code +" cannot be child item.")
raise Exception
# Check if is_main_item is modified once saved
#if not self.doc.fields.get('__islocal') and d.is_main_item == "Yes" and cstr(d.item_code) != cstr(self.doc.new_item_code)[:-3] :
# msgprint("Modifying the main item is not allowed.")
# raise Exception
if len(is_main_item) > 1:
msgprint('Main item cannot be more than one.')
raise Exception , " Validation Error."
@ -82,7 +78,6 @@ class DocType:
# ---------
def create_new_item(self):
i = Document("Item")
i.item_code = self.doc.new_item_code
i.item_name = self.doc.new_item_name
i.name = i.item_code
@ -106,7 +101,7 @@ class DocType:
sql("delete from `tabItem Price` where parent=%s and price_list_name = %s", (i.name, self.doc.price_list))
pld = addchild(i,"ref_rate_details", "Item Price")
pld.price_list_name = self.doc.price_List
pld.price_list_name = self.doc.price_list
pld.ref_rate = flt(ref_rate)
pld.ref_currency = self.doc.currency
pld.save()
@ -121,14 +116,11 @@ class DocType:
i.stock_uom = self.doc.stock_uom
i.item_group = self.doc.item_group
# update rates
new_rates = {}
self.update_ref_rate(i)
i.item_name = self.doc.new_item_name
i.description = self.doc.description
# set default as 'No' or 0 in Item Master as per TIC/3456
# set default as 'No' or 0
i.is_sample_item = 'No'
i.is_asset_item = 'No'
i.is_purchase_item = 'No'
@ -138,8 +130,10 @@ class DocType:
i.inspection_required = 'No'
i.has_serial_no = 'No'
i.lead_time_days = flt(0)
# update rates
self.update_ref_rate(i)
i.save()
msgprint("Items updated successfully.")
msgprint("Items: %s updated successfully. To update more details open and edit item master" % self.doc.new_item_code)
def validate(self):

View File

@ -32,7 +32,7 @@ convert_to_lists = webnotes.conn.convert_to_lists
# -----------------------------------------------------------------------------------------
def get_sr_no_list(sr_nos, qty = 0):
def get_sr_no_list(sr_nos, qty = 0, item_code = ''):
serial_nos = cstr(sr_nos).strip().replace(',', '\n').split('\n')
valid_serial_nos = []
for val in serial_nos:
@ -41,9 +41,8 @@ def get_sr_no_list(sr_nos, qty = 0):
msgprint("You have entered duplicate serial no: %s" % val, raise_exception=1)
else:
valid_serial_nos.append(val.strip())
if qty > 0 and cstr(sr_nos).strip() and len(valid_serial_nos) != flt(qty):
msgprint("Please enter serial nos for all "+ cstr(qty) + " quantity", raise_exception = 1)
if qty and cstr(sr_nos).strip() and len(valid_serial_nos) != abs(qty):
msgprint("Please enter serial nos for "+ cstr(abs(qty)) + " quantity against item code: " + item_code , raise_exception = 1)
return valid_serial_nos
class DocType:
@ -92,36 +91,46 @@ class DocType:
if is_stock_item != 'Yes':
msgprint("Serial No is not required for non-stock item: %s" % d.item_code, raise_exception=1)
elif ar_required != 'Yes':
msgprint("If serial no required, please select 'Yes' in 'Has Serial No' in Item :" + d.item_code + ', otherwise please remove serial no', raise_exception=1)
msgprint("If serial no required, please select 'Yes' in 'Has Serial No' in Item :" + d.item_code + \
', otherwise please remove serial no', raise_exception=1)
elif ar_required == 'Yes' and not d.serial_no:
msgprint("Serial no is mandatory for item: "+ d.item_code, raise_exception = 1)
# validate rejected serial nos
if fname == 'purchase_receipt_details' and d.rejected_qty and ar_required == 'Yes' and not d.rejected_serial_no:
msgprint("Rejected serial no is mandatory for rejected qty of item: "+ d.item_code, raise_exception = 1)
# -------------------
# get serial no list
# -------------------
def get_sr_no_list(self, sr_nos, qty = 0):
return get_sr_no_list(sr_nos, qty)
def get_sr_no_list(self, sr_nos, qty = 0, item_code = ''):
return get_sr_no_list(sr_nos, qty, item_code)
# ---------------------
# set serial no values
# ---------------------
def set_pur_serial_no_values(self, obj, serial_no, d, s, new_rec):
item_details = sql("select item_group, warranty_period from `tabItem` where name = '%s' and (ifnull(end_of_life,'')='' or end_of_life = '0000-00-00' or end_of_life > now()) " %(d.item_code), as_dict=1)
item_details = sql("select item_group, warranty_period from `tabItem` where name = '%s' and \
(ifnull(end_of_life,'')='' or end_of_life = '0000-00-00' or end_of_life > now()) " %(d.item_code), as_dict=1)
s.purchase_document_type = obj.doc.doctype
s.purchase_document_no = obj.doc.name
s.purchase_date = obj.doc.posting_date
s.purchase_time = obj.doc.posting_time
s.purchase_rate = d.valuation_rate or d.incoming_rate
s.item_code = d.item_code
s.item_name = d.item_name
s.brand = d.brand
s.description = d.description
s.item_group = item_details and item_details[0]['item_group'] or ''
s.warranty_period = item_details and item_details[0]['warranty_period'] or 0
s.supplier = obj.doc.supplier
s.supplier_name = obj.doc.supplier_name
s.supplier_address = obj.doc.supplier_address
s.address_display = obj.doc.address_display or obj.doc.supplier_address
s.warehouse = d.warehouse or d.t_warehouse
s.docstatus = 0
s.status = 'In Store'
@ -184,7 +193,7 @@ class DocType:
s.delivery_time = obj.doc.posting_time
s.customer = obj.doc.customer
s.customer_name = obj.doc.customer_name
s.delivery_address = obj.doc.delivery_address
s.delivery_address = obj.doc.address_display
s.territory = obj.doc.territory
s.warranty_expiry_date = s.warranty_period and add_days(cstr(obj.doc.posting_date), s.warranty_period) or ''
s.docstatus = 1
@ -220,6 +229,13 @@ class DocType:
else:
self.update_serial_delivery_details(obj, d, serial_no, is_submit)
if fname == 'purchase_receipt_details' and d.rejected_qty and d.rejected_serial_no:
serial_nos = self.get_sr_no_list(d.rejected_serial_no)
for a in serial_nos:
self.update_serial_purchase_details(obj, d, a, is_submit)
# -------------
# update stock
@ -227,21 +243,22 @@ class DocType:
def update_stock(self, values, is_amended = 'No'):
for v in values:
sle_id, serial_nos = '', ''
# get serial nos
if v["serial_no"]:
serial_nos = self.get_sr_no_list(v["serial_no"], v['actual_qty'])
serial_nos = self.get_sr_no_list(v["serial_no"], v['actual_qty'], v['item_code'])
# reverse quantities for cancel
if v['is_cancelled'] == 'Yes':
v['actual_qty'] = -flt(v['actual_qty'])
# cancel matching entry
sql("update `tabStock Ledger Entry` set is_cancelled='Yes' where voucher_no=%s and voucher_type=%s", (v['voucher_no'], v['voucher_type']))
sql("update `tabStock Ledger Entry` set is_cancelled='Yes' where voucher_no=%s \
and voucher_type=%s", (v['voucher_no'], v['voucher_type']))
if v["actual_qty"]:
sle_id = self.make_entry(v)
get_obj('Warehouse', v["warehouse"]).update_bin(flt(v["actual_qty"]), 0, 0, 0, 0, v["item_code"], v["posting_date"], sle_id, v["posting_time"], '', v["is_cancelled"],v["voucher_type"],v["voucher_no"], is_amended)
get_obj('Warehouse', v["warehouse"]).update_bin(flt(v["actual_qty"]), 0, 0, 0, 0, v["item_code"], \
v["posting_date"], sle_id, v["posting_time"], '', v["is_cancelled"],v["voucher_type"],v["voucher_no"], is_amended)
# -----------