[IMP] stock_planning: Corrected field names. Improved code.
bzr revid: uco@tinyerp.com-20100720101841-n6akm2gcstosesb7
This commit is contained in:
@@ -70,7 +70,7 @@ class stock_period_createlines(osv.osv_memory):
|
||||
'date_start': ds.strftime('%Y-%m-%d'),
|
||||
'date_stop': de.strftime('%Y-%m-%d %H:%M:%S'),
|
||||
})
|
||||
ds = ds + RelativeDateTime(days=interval)
|
||||
ds = ds + RelativeDateTime(days=interval) + 1
|
||||
if name =="Weekly":
|
||||
de = ds + RelativeDateTime(days=interval, minutes =-1)
|
||||
new_name = de.strftime('%Y, week %W')
|
||||
@@ -79,7 +79,7 @@ class stock_period_createlines(osv.osv_memory):
|
||||
'date_start': ds.strftime('%Y-%m-%d'),
|
||||
'date_stop': de.strftime('%Y-%m-%d %H:%M:%S'),
|
||||
})
|
||||
ds = ds + RelativeDateTime(days=interval)
|
||||
ds = ds + RelativeDateTime(days=interval) + 1
|
||||
if name == "Monthly":
|
||||
de = ds + RelativeDateTime(months=interval, minutes=-1)
|
||||
new_name = ds.strftime('%Y/%m')
|
||||
|
||||
@@ -31,14 +31,14 @@ class stock_planning_createlines(osv.osv_memory):
|
||||
def onchange_company(self, cr, uid, ids, company_id=False):
|
||||
result = {}
|
||||
if company_id:
|
||||
result['warehouse_id2'] = False
|
||||
result['warehouse_id'] = False
|
||||
return {'value': result}
|
||||
|
||||
_columns = {
|
||||
'company_id': fields.many2one('res.company', 'Company', required=True),
|
||||
'period_id2': fields.many2one('stock.period' , 'Period', required=True, help = 'Period which planning will concern.'),
|
||||
'warehouse_id2': fields.many2one('stock.warehouse' , 'Warehouse', required=True, help = 'Warehouse which planning will concern.'),
|
||||
'product_categ_id2': fields.many2one('product.category' , 'Product Category', \
|
||||
'period_id': fields.many2one('stock.period' , 'Period', required=True, help = 'Period which planning will concern.'),
|
||||
'warehouse_id': fields.many2one('stock.warehouse' , 'Warehouse', required=True, help = 'Warehouse which planning will concern.'),
|
||||
'product_categ_id': fields.many2one('product.category' , 'Product Category', \
|
||||
help = 'Planning will be created for products from Product Category selected by this field. '\
|
||||
'This field is ignored when you check \"All Forecasted Product\" box.' ),
|
||||
'forecasted_products': fields.boolean('All Products with Forecast', \
|
||||
@@ -66,7 +66,7 @@ class stock_planning_createlines(osv.osv_memory):
|
||||
WHERE (period_id = %s) AND (warehouse_id = %s)", (f.period_id2.id, f.warehouse_id2.id))
|
||||
products_id1 = [x for x, in cr.fetchall()]
|
||||
else:
|
||||
categ_ids = f.product_categ_id2.id and [f.product_categ_id2.id] or []
|
||||
categ_ids = f.product_categ_id.id and [f.product_categ_id.id] or []
|
||||
prod_categ_ids = prod_categ_obj.search(cr,uid,[('parent_id','child_of',categ_ids)])
|
||||
templates_ids = template_obj.search(cr,uid,[('categ_id','in',prod_categ_ids)])
|
||||
products_id1 = product_obj.search(cr,uid,[('product_tmpl_id','in',templates_ids)])
|
||||
@@ -75,8 +75,8 @@ class stock_planning_createlines(osv.osv_memory):
|
||||
|
||||
for p in product_obj.browse(cr, uid, products_id1,context=context):
|
||||
if len(planning_obj.search(cr, uid, [('product_id','=',p.id),
|
||||
('period_id','=',f.period_id2.id),
|
||||
('warehouse_id','=',f.warehouse_id2.id)]))== 0:
|
||||
('period_id','=',f.period_id.id),
|
||||
('warehouse_id','=',f.warehouse_id.id)]))== 0:
|
||||
cr.execute("SELECT period.date_stop, planning.product_uom, planning.planned_outgoing, planning.to_procure, \
|
||||
planning.stock_only, planning.procure_to_stock, planning.confirmed_forecasts_only, \
|
||||
planning.supply_warehouse_id, planning.stock_supply_location \
|
||||
@@ -87,7 +87,7 @@ class stock_planning_createlines(osv.osv_memory):
|
||||
AND planning.warehouse_id = %s AND planning.product_id = %s \
|
||||
AND period.date_stop < %s \
|
||||
ORDER BY period.date_stop DESC",
|
||||
(uid, uid, f.warehouse_id2.id, p.id, f.period_id2.date_stop) )
|
||||
(uid, uid, f.warehouse_id.id, p.id, f.period_id.date_stop) )
|
||||
ret=cr.fetchone()
|
||||
# forecast_qty = ret and ret[0] or 0.0
|
||||
if ret:
|
||||
@@ -113,9 +113,9 @@ class stock_planning_createlines(osv.osv_memory):
|
||||
if p.uos_id:
|
||||
prod_uos_categ = p.uos_id.category_id.id
|
||||
planning_lines.append(planning_obj.create(cr, uid, {
|
||||
'company_id' : f.warehouse_id2.company_id.id,
|
||||
'period_id': f.period_id2.id,
|
||||
'warehouse_id' : f.warehouse_id2.id,
|
||||
'company_id' : f.warehouse_id.company_id.id,
|
||||
'period_id': f.period_id.id,
|
||||
'warehouse_id' : f.warehouse_id.id,
|
||||
'product_id': p.id,
|
||||
'product_uom' : prod_uom,
|
||||
'product_uom_categ' : p.uom_id.category_id.id,
|
||||
|
||||
@@ -12,13 +12,13 @@
|
||||
<form string="Stock Planning">
|
||||
<field name="company_id" widget= "selection" on_change="onchange_company(company_id)" groups="base.group_multi_company"/>
|
||||
<newline/>
|
||||
<field name="period_id2" widget="selection"/>
|
||||
<field name="period_id" widget="selection"/>
|
||||
<newline/>
|
||||
<field name="warehouse_id2" domain = "[('company_id','=',company_id)] "/>
|
||||
<field name="warehouse_id" domain = "[('company_id','=',company_id)] "/>
|
||||
<newline/>
|
||||
<field name="forecasted_products"/>
|
||||
<newline/>
|
||||
<field name="product_categ_id2" attrs="{'required':[('forecasted_products','=',0)]}" widget="selection"/>
|
||||
<field name="product_categ_id" attrs="{'required':[('forecasted_products','=',0)]}" widget="selection"/>
|
||||
<separator colspan ="4" string="Stock planning lines creation"/>
|
||||
<label colspan ="4" string="Creates planning lines for selected period and warehouse. Doesn't duplicate existing lines created by you."/>
|
||||
<group colspan="4">
|
||||
|
||||
@@ -38,11 +38,11 @@ class stock_sale_forecast_createlines(osv.osv_memory):
|
||||
|
||||
_columns = {
|
||||
'company_id': fields.many2one('res.company', 'Company', required=True, select=1),
|
||||
'warehouse_id1': fields.many2one('stock.warehouse' , 'Warehouse', required=True, \
|
||||
'warehouse_id': fields.many2one('stock.warehouse' , 'Warehouse', required=True, \
|
||||
help='Warehouse which forecasts will concern. '\
|
||||
'If during stock planning you will need sales forecast for all warehouses choose any warehouse now.'),
|
||||
'period_id1': fields.many2one('stock.period' , 'Period', required=True, help = 'Period which forecasts will concern.' ),
|
||||
'product_categ_id1': fields.many2one('product.category' , 'Product Category', required=True, \
|
||||
'period_id': fields.many2one('stock.period' , 'Period', required=True, help = 'Period which forecasts will concern.' ),
|
||||
'product_categ_id': fields.many2one('product.category' , 'Product Category', required=True, \
|
||||
help ='Product Category of products which created forecasts will concern.'),
|
||||
'copy_forecast': fields.boolean('Copy Last Forecast', help="Copy quantities from last Stock and Sale Forecast."),
|
||||
}
|
||||
@@ -59,7 +59,7 @@ class stock_sale_forecast_createlines(osv.osv_memory):
|
||||
template_obj = self.pool.get('product.template')
|
||||
forecast_lines = []
|
||||
for f in self.browse(cr, uid, ids, context=context):
|
||||
categ_ids = f.product_categ_id1.id and [f.product_categ_id1.id] or []
|
||||
categ_ids = f.product_categ_id.id and [f.product_categ_id.id] or []
|
||||
prod_categ_ids = prod_categ_obj.search(cr, uid, [('parent_id','child_of', categ_ids)])
|
||||
templates_ids = template_obj.search(cr, uid, [('categ_id','in',prod_categ_ids)])
|
||||
products_ids = product_obj.search(cr, uid, [('product_tmpl_id','in',templates_ids)])
|
||||
@@ -68,9 +68,9 @@ class stock_sale_forecast_createlines(osv.osv_memory):
|
||||
copy = f.copy_forecast
|
||||
for p in product_obj.browse(cr, uid, products_ids,{}):
|
||||
if len(forecast_obj.search(cr, uid, [('product_id','=',p.id) , \
|
||||
('period_id','=',f.period_id1.id), \
|
||||
('period_id','=',f.period_id.id), \
|
||||
('user_id','=',uid), \
|
||||
('warehouse_id','=',f.warehouse_id1.id)]))== 0:
|
||||
('warehouse_id','=',f.warehouse_id.id)]))== 0:
|
||||
forecast_qty = 0.0
|
||||
# Not sure if it is expected quantity for this feature (copying forecast from previous period)
|
||||
# because it can take incidental forecast of this warehouse, this product and this user (creating, writing or validating forecast).
|
||||
@@ -86,7 +86,7 @@ class stock_sale_forecast_createlines(osv.osv_memory):
|
||||
AND forecast.warehouse_id = %s AND forecast.product_id = %s \
|
||||
AND period.date_stop < %s \
|
||||
ORDER BY period.date_stop DESC",
|
||||
(uid, uid, uid, f.warehouse_id1.id, p.id, f.period_id1.date_stop) )
|
||||
(uid, uid, uid, f.warehouse_id.id, p.id, f.period_id.date_stop) )
|
||||
ret = cr.fetchone()
|
||||
if ret:
|
||||
forecast_qty = ret[1]
|
||||
@@ -96,9 +96,9 @@ class stock_sale_forecast_createlines(osv.osv_memory):
|
||||
if p.uos_id:
|
||||
prod_uos_categ = p.uos_id.category_id.id
|
||||
forecast_lines.append(forecast_obj.create(cr, uid, {
|
||||
'company_id': f.warehouse_id1.company_id.id,
|
||||
'period_id': f.period_id1.id,
|
||||
'warehouse_id': f.warehouse_id1.id,
|
||||
'company_id': f.warehouse_id.company_id.id,
|
||||
'period_id': f.period_id.id,
|
||||
'warehouse_id': f.warehouse_id.id,
|
||||
'product_id': p.id,
|
||||
'product_qty': forecast_qty,
|
||||
'product_amt': 0.0,
|
||||
|
||||
@@ -12,11 +12,11 @@
|
||||
<form string="Stock and Sales Forecasts">
|
||||
<field name="company_id" groups="base.group_multi_company" widget="selection"/>
|
||||
<newline/>
|
||||
<field name="period_id1"/>
|
||||
<field name="period_id"/>
|
||||
<newline/>
|
||||
<field name="warehouse_id1" domain = "[('company_id','=',company_id)] "/>
|
||||
<field name="warehouse_id" domain = "[('company_id','=',company_id)] "/>
|
||||
<newline/>
|
||||
<field name="product_categ_id1" widget="selection"/>
|
||||
<field name="product_categ_id" widget="selection"/>
|
||||
<newline/>
|
||||
<field name="copy_forecast"/>
|
||||
<separator colspan ="4" string="Forecast lines creation"/>
|
||||
|
||||
Reference in New Issue
Block a user