allow negative qty feature

This commit is contained in:
Nabin Hait 2012-04-18 12:04:20 +05:30
parent 69e7eb4f3d
commit 7afc2124a6
4 changed files with 415 additions and 375 deletions

View File

@ -34,7 +34,8 @@ keydict = {
'valuation_method': 'default_valuation_method',
'date_format': 'date_format',
'currency_format':'default_currency_format',
'account_url':'account_url'
'account_url':'account_url',
'allow_negative_stock' : 'allow_negative_stock'
}
class DocType:
@ -66,4 +67,4 @@ class DocType:
get_last_day(get_first_day(ysd,0,11)).strftime('%Y-%m-%d'))
def get_defaults(self):
return webnotes.conn.get_defaults()
return webnotes.conn.get_defaults()

View File

@ -185,8 +185,6 @@ class DocType:
def get_moving_average_inventory_values(self, val_rate, in_rate, opening_qty, actual_qty, is_cancelled):
if flt(in_rate) <= 0: # In case of delivery/stock issue in_rate = 0 or wrong incoming rate
in_rate = val_rate
if in_rate and val_rate == 0: # First entry
val_rate = in_rate
# val_rate is same as previous entry if :
# 1. actual qty is negative(delivery note / stock entry)
@ -194,7 +192,11 @@ class DocType:
# 3. val_rate is negative
# Otherwise it will be calculated as per moving average
elif actual_qty > 0 and (opening_qty + actual_qty) > 0 and is_cancelled == 'No' and ((opening_qty * val_rate) + (actual_qty * in_rate)) > 0:
if opening_qty < 0:
opening_qty = 0
val_rate = ((opening_qty *val_rate) + (actual_qty * in_rate)) / (opening_qty + actual_qty)
elif (opening_qty + actual_qty) <= 0:
val_rate = 0
stock_val = val_rate
return val_rate, stock_val
@ -277,6 +279,11 @@ class DocType:
# get valuation method
val_method = get_obj('Valuation Control').get_valuation_method(self.doc.item_code)
# allow negative stock (only for moving average method)
from webnotes.utils import get_defaults
allow_negative_stock = get_defaults().get('allow_negative_stock', 0)
# recalculate the balances for all stock ledger entries
# after the prev sle
sll = sql("""
@ -289,10 +296,10 @@ class DocType:
order by timestamp(posting_date, posting_time) asc, name asc""", \
(self.doc.item_code, self.doc.warehouse, \
prev_sle.get('posting_date','1900-01-01'), prev_sle.get('posting_time', '12:00')), as_dict = 1)
for sle in sll:
# block if stock level goes negative on any date
self.validate_negative_stock(cqty, sle)
if val_method != 'Moving Average' or flt(allow_negative_stock) == 0:
self.validate_negative_stock(cqty, sle)
stock_val, in_rate = 0, sle['incoming_rate'] # IN
serial_nos = sle["serial_no"] and ("'"+"', '".join(cstr(sle["serial_no"]).split('\n')) \

View File

@ -265,9 +265,6 @@ class DocType(TransactionBase):
if flt(d.transfer_qty) <= 0:
msgprint("Transfer Quantity can not be less than or equal to zero at Row No " + cstr(d.idx))
raise Exception
if d.s_warehouse and flt(d.transfer_qty) > flt(d.actual_qty):
msgprint("Transfer Quantity is more than Available Qty at Row No " + cstr(d.idx))
raise Exception
def calc_amount(self):

View File

@ -3,52 +3,59 @@
# These values are common in all dictionaries
{
'creation': '2010-08-08 17:09:25',
'creation': '2009-05-12 16:46:51',
'docstatus': 0,
'modified': '2011-06-02 15:42:37',
'modified_by': 'Administrator',
'owner': 'Administrator'
'modified': '2012-04-18 11:59:34',
'modified_by': u'Administrator',
'owner': u'Administrator'
},
# These values are common for all DocType
{
'_last_update': '1309508840',
'autoname': 'SLE/.########',
'colour': 'White:FFF',
'_last_update': u'1334728856',
'autoname': u'SLE/.########',
'colour': u'White:FFF',
'doctype': 'DocType',
'hide_toolbar': 1,
'in_create': 1,
'module': 'Stock',
'module': u'Stock',
'name': '__common__',
'section_style': 'Simple',
'server_code_error': ' ',
'section_style': u'Simple',
'server_code_error': u' ',
'show_in_menu': 0,
'version': 53
'version': 54
},
# These values are common for all DocField
{
'doctype': 'DocField',
'doctype': u'DocField',
'name': '__common__',
'parent': 'Stock Ledger Entry',
'parentfield': 'fields',
'parenttype': 'DocType'
'parent': u'Stock Ledger Entry',
'parentfield': u'fields',
'parenttype': u'DocType'
},
# These values are common for all DocPerm
{
'doctype': 'DocPerm',
'doctype': u'DocPerm',
'name': '__common__',
'parent': 'Stock Ledger Entry',
'parentfield': 'permissions',
'parenttype': 'DocType',
'parent': u'Stock Ledger Entry',
'parentfield': u'permissions',
'parenttype': u'DocType',
'read': 1
},
# DocType, Stock Ledger Entry
{
'doctype': 'DocType',
'name': 'Stock Ledger Entry'
'name': u'Stock Ledger Entry'
},
# DocPerm
{
'doctype': u'DocPerm',
'permlevel': 1,
'role': u'All'
},
# DocPerm
@ -56,392 +63,420 @@
'amend': 0,
'cancel': 0,
'create': 0,
'doctype': 'DocPerm',
'idx': 1,
'doctype': u'DocPerm',
'permlevel': 1,
'role': u'Material User',
'submit': 0,
'write': 0
},
# DocPerm
{
'amend': 0,
'cancel': 0,
'create': 0,
'doctype': u'DocPerm',
'permlevel': 0,
'role': 'Material User',
'role': u'Material User',
'submit': 0,
'write': 0
},
# DocPerm
{
'doctype': 'DocPerm',
'idx': 2,
'permlevel': 1,
'role': 'All'
},
# DocPerm
{
'amend': 0,
'cancel': 0,
'create': 0,
'doctype': 'DocPerm',
'idx': 3,
'permlevel': 1,
'role': 'Material User',
'submit': 0,
'write': 0
},
# DocPerm
{
'doctype': 'DocPerm',
'idx': 4,
'doctype': u'DocPerm',
'permlevel': 2,
'role': 'System Manager'
'role': u'System Manager'
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'item_code',
'fieldtype': 'Link',
'idx': 1,
'in_filter': 1,
'label': 'Item Code',
'oldfieldname': 'item_code',
'oldfieldtype': 'Link',
'options': 'Item',
'permlevel': 1,
'reqd': 0,
'search_index': 1,
'width': '100px'
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'serial_no',
'fieldtype': 'Text',
'idx': 2,
'in_filter': 0,
'label': 'Serial No',
'permlevel': 0,
'search_index': 0,
'width': '100px'
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'batch_no',
'fieldtype': 'Data',
'idx': 3,
'label': 'Batch No',
'oldfieldname': 'batch_no',
'oldfieldtype': 'Data',
'permlevel': 0
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'warehouse',
'fieldtype': 'Link',
'idx': 4,
'in_filter': 1,
'label': 'Warehouse',
'oldfieldname': 'warehouse',
'oldfieldtype': 'Link',
'options': 'Warehouse',
'permlevel': 1,
'search_index': 1,
'width': '100px'
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'warehouse_type',
'fieldtype': 'Select',
'idx': 5,
'in_filter': 1,
'label': 'Warehouse Type',
'oldfieldname': 'warehouse_type',
'oldfieldtype': 'Select',
'options': 'link:Warehouse Type',
'permlevel': 1,
'search_index': 0
},
# DocField
{
'description': 'The date at which current entry will get or has actually executed.',
'doctype': 'DocField',
'fieldname': 'posting_date',
'fieldtype': 'Date',
'idx': 6,
'in_filter': 1,
'label': 'Posting Date',
'oldfieldname': 'posting_date',
'oldfieldtype': 'Date',
'permlevel': 1,
'reqd': 0,
'search_index': 1,
'width': '100px'
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'posting_time',
'fieldtype': 'Time',
'idx': 7,
'in_filter': 0,
'label': 'Posting Time',
'oldfieldname': 'posting_time',
'oldfieldtype': 'Time',
'permlevel': 1,
'search_index': 1,
'width': '100px'
},
# DocField
{
'description': 'The date at which current entry is made in system.',
'doctype': 'DocField',
'fieldname': 'transaction_date',
'fieldtype': 'Date',
'idx': 8,
'in_filter': 1,
'label': 'Transaction Date',
'oldfieldname': 'transaction_date',
'oldfieldtype': 'Date',
'permlevel': 1,
'search_index': 0,
'width': '100px'
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'voucher_type',
'fieldtype': 'Data',
'idx': 9,
'in_filter': 1,
'label': 'Voucher Type',
'oldfieldname': 'voucher_type',
'oldfieldtype': 'Data',
'permlevel': 1,
'search_index': 0,
'width': '150px'
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'voucher_no',
'fieldtype': 'Data',
'idx': 10,
'in_filter': 1,
'label': 'Voucher No',
'oldfieldname': 'voucher_no',
'oldfieldtype': 'Data',
'permlevel': 1,
'search_index': 0,
'width': '150px'
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'voucher_detail_no',
'fieldtype': 'Data',
'idx': 11,
'label': 'Voucher Detail No',
'oldfieldname': 'voucher_detail_no',
'oldfieldtype': 'Data',
'permlevel': 1,
'width': '150px'
},
# DocField
{
'colour': 'White:FFF',
'doctype': 'DocField',
'fieldname': 'actual_qty',
'fieldtype': 'Currency',
'idx': 12,
'in_filter': 1,
'label': 'Actual Quantity',
'oldfieldname': 'actual_qty',
'oldfieldtype': 'Currency',
'permlevel': 1,
'width': '150px'
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'incoming_rate',
'fieldtype': 'Currency',
'idx': 13,
'label': 'Incoming Rate',
'oldfieldname': 'incoming_rate',
'oldfieldtype': 'Currency',
'permlevel': 0
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'stock_uom',
'fieldtype': 'Data',
'idx': 14,
'label': 'Stock UOM',
'oldfieldname': 'stock_uom',
'oldfieldtype': 'Data',
'permlevel': 1,
'width': '150px'
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'bin_aqat',
'fieldtype': 'Currency',
'idx': 15,
'in_filter': 1,
'label': 'Bin Actual Qty After Transaction',
'oldfieldname': 'bin_aqat',
'oldfieldtype': 'Currency',
'permlevel': 1,
'width': '150px'
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'ma_rate',
'fieldtype': 'Currency',
'hidden': 1,
'idx': 16,
'label': 'Moving Average Rate',
'oldfieldname': 'ma_rate',
'oldfieldtype': 'Currency',
'permlevel': 0,
'print_hide': 1,
'report_hide': 1
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'fcfs_rate',
'fieldtype': 'Currency',
'hidden': 1,
'idx': 17,
'label': 'FIFO Rate',
'oldfieldname': 'fcfs_rate',
'oldfieldtype': 'Currency',
'permlevel': 0,
'print_hide': 1,
'report_hide': 1
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'valuation_rate',
'fieldtype': 'Currency',
'idx': 18,
'label': 'Valuation Rate',
'oldfieldname': 'valuation_rate',
'oldfieldtype': 'Currency',
'permlevel': 0,
'width': '150px'
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'stock_value',
'fieldtype': 'Currency',
'idx': 19,
'label': 'Stock Value',
'oldfieldname': 'stock_value',
'oldfieldtype': 'Currency',
'permlevel': 0
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'fcfs_stack',
'fieldtype': 'Text',
'doctype': u'DocField',
'fieldname': u'item_code',
'fieldtype': u'Link',
'hidden': 0,
'idx': 20,
'in_filter': 1,
'label': u'Item Code',
'oldfieldname': u'item_code',
'oldfieldtype': u'Link',
'options': u'Item',
'permlevel': 1,
'print_hide': 0,
'reqd': 0,
'search_index': 1,
'width': u'100px'
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'serial_no',
'fieldtype': u'Text',
'in_filter': 0,
'label': 'FIFO Stack',
'oldfieldname': 'fcfs_stack',
'oldfieldtype': 'Text',
'label': u'Serial No',
'permlevel': 0,
'search_index': 0,
'width': u'100px'
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'batch_no',
'fieldtype': u'Data',
'hidden': 0,
'label': u'Batch No',
'oldfieldname': u'batch_no',
'oldfieldtype': u'Data',
'permlevel': 0,
'print_hide': 0,
'reqd': 0
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'warehouse',
'fieldtype': u'Link',
'hidden': 0,
'in_filter': 1,
'label': u'Warehouse',
'oldfieldname': u'warehouse',
'oldfieldtype': u'Link',
'options': u'Warehouse',
'permlevel': 1,
'print_hide': 0,
'reqd': 0,
'search_index': 1,
'width': u'100px'
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'warehouse_type',
'fieldtype': u'Select',
'hidden': 0,
'in_filter': 1,
'label': u'Warehouse Type',
'oldfieldname': u'warehouse_type',
'oldfieldtype': u'Select',
'options': u'\nStores',
'permlevel': 1,
'print_hide': 0,
'reqd': 0,
'search_index': 1
},
# DocField
{
'description': u'The date at which current entry will get or has actually executed.',
'doctype': u'DocField',
'fieldname': u'posting_date',
'fieldtype': u'Date',
'hidden': 0,
'in_filter': 1,
'label': u'Posting Date',
'oldfieldname': u'posting_date',
'oldfieldtype': u'Date',
'permlevel': 1,
'print_hide': 0,
'reqd': 0,
'search_index': 1,
'width': u'100px'
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'posting_time',
'fieldtype': u'Time',
'hidden': 0,
'in_filter': 0,
'label': u'Posting Time',
'oldfieldname': u'posting_time',
'oldfieldtype': u'Time',
'permlevel': 1,
'print_hide': 0,
'reqd': 0,
'search_index': 0,
'width': u'100px'
},
# 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,
'in_filter': 1,
'label': u'Transaction Date',
'oldfieldname': u'transaction_date',
'oldfieldtype': u'Date',
'permlevel': 1,
'print_hide': 0,
'reqd': 0,
'search_index': 1,
'width': u'100px'
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'voucher_type',
'fieldtype': u'Data',
'hidden': 0,
'in_filter': 1,
'label': u'Voucher Type',
'oldfieldname': u'voucher_type',
'oldfieldtype': u'Data',
'permlevel': 1,
'print_hide': 0,
'reqd': 0,
'search_index': 1,
'width': u'150px'
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'voucher_no',
'fieldtype': u'Data',
'hidden': 0,
'in_filter': 1,
'label': u'Voucher No',
'oldfieldname': u'voucher_no',
'oldfieldtype': u'Data',
'permlevel': 1,
'print_hide': 0,
'reqd': 0,
'search_index': 1,
'width': u'150px'
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'voucher_detail_no',
'fieldtype': u'Data',
'hidden': 0,
'label': u'Voucher Detail No',
'oldfieldname': u'voucher_detail_no',
'oldfieldtype': u'Data',
'permlevel': 1,
'print_hide': 0,
'reqd': 0,
'width': u'150px'
},
# DocField
{
'colour': u'White:FFF',
'doctype': u'DocField',
'fieldname': u'actual_qty',
'fieldtype': u'Currency',
'hidden': 0,
'in_filter': 1,
'label': u'Actual Quantity',
'oldfieldname': u'actual_qty',
'oldfieldtype': u'Currency',
'permlevel': 1,
'print_hide': 0,
'reqd': 0,
'width': u'150px'
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'incoming_rate',
'fieldtype': u'Currency',
'hidden': 0,
'label': u'Incoming Rate',
'oldfieldname': u'incoming_rate',
'oldfieldtype': u'Currency',
'permlevel': 0,
'print_hide': 0,
'reqd': 0
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'stock_uom',
'fieldtype': u'Data',
'hidden': 0,
'label': u'Stock UOM',
'oldfieldname': u'stock_uom',
'oldfieldtype': u'Data',
'permlevel': 1,
'print_hide': 0,
'reqd': 0,
'width': u'150px'
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'bin_aqat',
'fieldtype': u'Currency',
'hidden': 0,
'in_filter': 1,
'label': u'Bin Actual Qty After Transaction',
'oldfieldname': u'bin_aqat',
'oldfieldtype': u'Currency',
'permlevel': 1,
'print_hide': 0,
'reqd': 0,
'width': u'150px'
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'ma_rate',
'fieldtype': u'Currency',
'hidden': 1,
'label': u'Moving Average Rate',
'oldfieldname': u'ma_rate',
'oldfieldtype': u'Currency',
'permlevel': 0,
'print_hide': 1,
'report_hide': 0,
'report_hide': 1,
'reqd': 0
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'fcfs_rate',
'fieldtype': u'Currency',
'hidden': 1,
'label': u'FIFO Rate',
'oldfieldname': u'fcfs_rate',
'oldfieldtype': u'Currency',
'permlevel': 0,
'print_hide': 1,
'report_hide': 1,
'reqd': 0
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'valuation_rate',
'fieldtype': u'Currency',
'hidden': 0,
'label': u'Valuation Rate',
'oldfieldname': u'valuation_rate',
'oldfieldtype': u'Currency',
'permlevel': 0,
'print_hide': 0,
'reqd': 0,
'width': u'150px'
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'stock_value',
'fieldtype': u'Currency',
'hidden': 0,
'label': u'Stock Value',
'oldfieldname': u'stock_value',
'oldfieldtype': u'Currency',
'permlevel': 0,
'print_hide': 0,
'reqd': 0
},
# DocField
{
'colour': u'White:FFF',
'doctype': u'DocField',
'fieldname': u'fcfs_stack',
'fieldtype': u'Text',
'hidden': 1,
'in_filter': 0,
'label': u'FIFO Stack',
'oldfieldname': u'fcfs_stack',
'oldfieldtype': u'Text',
'permlevel': 2,
'print_hide': 1,
'report_hide': 1,
'reqd': 0,
'search_index': 0
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'company',
'fieldtype': 'Data',
'idx': 21,
'doctype': u'DocField',
'fieldname': u'company',
'fieldtype': u'Select',
'hidden': 0,
'in_filter': 1,
'label': 'Company',
'oldfieldname': 'company',
'oldfieldtype': 'Data',
'label': u'Company',
'oldfieldname': u'company',
'oldfieldtype': u'Data',
'options': u'\nWeb Notes Technologies Pvt Ltd',
'permlevel': 1,
'search_index': 0,
'width': '150px'
'print_hide': 0,
'reqd': 0,
'search_index': 1,
'width': u'150px'
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'fiscal_year',
'fieldtype': 'Data',
'idx': 22,
'doctype': u'DocField',
'fieldname': u'fiscal_year',
'fieldtype': u'Data',
'hidden': 0,
'in_filter': 1,
'label': 'Fiscal Year',
'oldfieldname': 'fiscal_year',
'oldfieldtype': 'Data',
'label': u'Fiscal Year',
'oldfieldname': u'fiscal_year',
'oldfieldtype': u'Data',
'permlevel': 1,
'search_index': 0,
'width': '150px'
'print_hide': 0,
'reqd': 0,
'search_index': 1,
'width': u'150px'
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'is_cancelled',
'fieldtype': 'Select',
'idx': 23,
'doctype': u'DocField',
'fieldname': u'is_cancelled',
'fieldtype': u'Select',
'hidden': 0,
'in_filter': 1,
'label': 'Is Cancelled',
'oldfieldname': 'is_cancelled',
'oldfieldtype': 'Select',
'options': '\nYes\nNo',
'label': u'Is Cancelled',
'oldfieldname': u'is_cancelled',
'oldfieldtype': u'Select',
'options': u'\nYes\nNo',
'permlevel': 1,
'search_index': 0,
'width': '100px'
'print_hide': 0,
'reqd': 0,
'search_index': 1,
'width': u'100px'
},
# DocField
{
'doctype': 'DocField',
'fieldname': 'is_stock_entry',
'fieldtype': 'Select',
'idx': 24,
'doctype': u'DocField',
'fieldname': u'is_stock_entry',
'fieldtype': u'Select',
'hidden': 0,
'in_filter': 1,
'label': 'Is Stock Entry',
'oldfieldname': 'is_stock_entry',
'oldfieldtype': 'Select',
'options': '\nYes\nNo',
'label': u'Is Stock Entry',
'oldfieldname': u'is_stock_entry',
'oldfieldtype': u'Select',
'options': u'\nYes\nNo',
'permlevel': 1,
'search_index': 0,
'width': '100px'
'print_hide': 0,
'reqd': 0,
'search_index': 1,
'width': u'100px'
}
]