[IMP] stock_account: standard price historization did it in my own way
bzr revid: qdp-launchpad@openerp.com-20131029150959-rbv9lyzhcx6pi4vc
This commit is contained in:
parent
acb241ed37
commit
5d3ea94d6b
|
@ -1196,6 +1196,12 @@ class stock_move(osv.osv):
|
|||
res.append((line.id, name))
|
||||
return res
|
||||
|
||||
def create(self, cr, uid, vals, context=None):
|
||||
if vals.get('product_id') and not vals.get('price_unit'):
|
||||
prod_obj = self.pool.get('product.product')
|
||||
vals['price_unit'] = prod_obj.browse(cr, uid, vals['product_id'], context=context).standard_price
|
||||
return super(stock_move, self).create(cr, uid, vals, context=context)
|
||||
|
||||
# FP Note: put this on quants, with the auto creation algo
|
||||
# def _check_tracking(self, cr, uid, ids, context=None):
|
||||
# """ Checks if serial number is assigned to stock move or not.
|
||||
|
@ -1332,7 +1338,7 @@ class stock_move(osv.osv):
|
|||
"* Available: When products are reserved, it is set to \'Available\'.\n"\
|
||||
"* Done: When the shipment is processed, the state is \'Done\'."),
|
||||
|
||||
'price_unit': fields.float('Unit Price', help="Technical field used to record the product cost set by the user during a picking confirmation (when average price costing method is used). Value given in company currency and in product uom."), # as it's a technical field, we intentionally don't provide the digits attribute
|
||||
'price_unit': fields.float('Unit Price', help="Technical field used to record the product cost set by the user during a picking confirmation (when costing method used is 'average price' or 'real'). Value given in company currency and in product uom."), # as it's a technical field, we intentionally don't provide the digits attribute
|
||||
|
||||
'company_id': fields.many2one('res.company', 'Company', required=True, select=True),
|
||||
'backorder_id': fields.related('picking_id','backorder_id',type='many2one', relation="stock.picking", string="Back Order of", select=True),
|
||||
|
|
|
@ -166,27 +166,35 @@ class product_product(osv.osv):
|
|||
|
||||
return move_ids
|
||||
|
||||
def create(self, cr, uid, vals, context=None):
|
||||
product_id = super(product_product, self).create(cr, uid, vals, context=context)
|
||||
price_history_obj = self.pool['prices.history']
|
||||
if vals.get('cost_method') in ('standard', 'average'):
|
||||
price_history_obj.create(cr, uid, {
|
||||
'product_id': product_id,
|
||||
'cost': vals.get('standard_price', 0.0),
|
||||
'reason': 'standard_price is set',
|
||||
}, context=context)
|
||||
|
||||
def write(self, cr, uid, ids, values, context=None):
|
||||
if 'standard_price' in values:
|
||||
standard_prices = self.pool['standard.prices']
|
||||
price_history_obj = self.pool['prices.history']
|
||||
for product in self.browse(cr, uid, ids, context=context):
|
||||
data = {
|
||||
'product_id': product.id,
|
||||
'cost': values['standard_price'],
|
||||
'reason': 'standard_price is changed.',
|
||||
# Provided by self._defaults:
|
||||
# 'company_id':
|
||||
# 'quant_id':
|
||||
# 'datetime':
|
||||
}
|
||||
if product.cost_method in ('standard', 'average'):
|
||||
standard_prices.create(cr, uid, data, context=context)
|
||||
price_history_obj.create(cr, uid, {
|
||||
'product_id': product.id,
|
||||
'cost': values['standard_price'],
|
||||
'reason': 'standard_price is changed.',
|
||||
# Provided by self._defaults:
|
||||
# 'company_id':
|
||||
# 'quant_id':
|
||||
# 'datetime':
|
||||
}, context=context)
|
||||
elif product.cost_method in ('real',):
|
||||
# For a 'real' cost_method, entries in standard_prices are
|
||||
# created when quants are created.
|
||||
# created when quants are created. #TODO not true
|
||||
pass
|
||||
return super(product_product, self).write(cr, uid, ids, values,
|
||||
context=context)
|
||||
return super(product_product, self).write(cr, uid, ids, values, context=context)
|
||||
|
||||
_columns = {
|
||||
'valuation':fields.property(type='selection', selection=[('manual_periodic', 'Periodical (manual)'),
|
||||
|
|
|
@ -91,6 +91,34 @@
|
|||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.view" id="view_stock_history_tree">
|
||||
<field name="name">stock.history.tree</field>
|
||||
<field name="model">stock.history</field>
|
||||
<field eval="12" name="priority"/>
|
||||
<field name="arch" type="xml">
|
||||
<tree string="Stock">
|
||||
<field name="move_id" invisible="1"/>
|
||||
<field name="location_id"/>
|
||||
<field name="product_id"/>
|
||||
<field name="quantity"/>
|
||||
<field name="date"/>
|
||||
<field name="cost"/>
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="action_stock_history_report" model="ir.actions.act_window">
|
||||
<field name="name">Stock History</field>
|
||||
<field name="res_model">stock.history</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">tree,graph,form</field>
|
||||
<field name="view_id" ref="view_stock_history_tree"/>
|
||||
<!--<field name="context">{'search_default_real':1, 'search_default_inmovesremaining':1 ,'group_by':['company_id', 'product_id'], 'group_by_no_leaf':0}</field>
|
||||
<field name="help">Inventory Analysis allows you to easily check and analyse your company stock levels. Sort and group by selection criteria in order to better analyse and manage your company activities.</field>-->
|
||||
</record>
|
||||
<menuitem action="action_stock_history_report"
|
||||
id="menu_action_stock_history_report"
|
||||
parent="stock.next_id_61" sequence="5"/>
|
||||
</data>
|
||||
</openerp>
|
||||
|
|
|
@ -1,18 +1,13 @@
|
|||
"""
|
||||
Keep track of the ``product.product`` standard prices as they are changed.
|
||||
|
||||
The ``standard.prices`` model records each ``standard`` or ``average``
|
||||
``cost_method`` change. For the ``real`` ``cost_method`` it records every
|
||||
wuants creation.
|
||||
|
||||
"""
|
||||
|
||||
from openerp import tools
|
||||
from openerp.osv import fields, osv
|
||||
|
||||
class price_history(osv.osv):
|
||||
class prices_history(osv.osv):
|
||||
"""
|
||||
Keep track of the ``product.product`` standard prices as they are changed.
|
||||
"""
|
||||
|
||||
_name = 'price.history'
|
||||
_name = 'prices.history'
|
||||
_rec_name = 'datetime'
|
||||
|
||||
_columns = {
|
||||
|
@ -52,6 +47,7 @@ class stock_history(osv.osv):
|
|||
'quantity': fields.integer('Quantity'),
|
||||
'date': fields.datetime('Date'),
|
||||
'cost': fields.float('Value'),
|
||||
'cost_method': fields.char('Cost Method'),
|
||||
}
|
||||
|
||||
def init(self, cr):
|
||||
|
@ -65,9 +61,10 @@ class stock_history(osv.osv):
|
|||
stock_move.product_id AS product_id,
|
||||
stock_move.product_qty AS quantity,
|
||||
stock_move.date AS date,
|
||||
ir_property.value_text AS cost_method,
|
||||
CASE
|
||||
WHEN ir_property.value_text <> 'real'
|
||||
THEN (SELECT price_history.cost FROM price_history WHERE price_history.datetime <= stock_move.date AND price_history.product_id = stock_move.product_id ORDER BY price_history.datetime ASC limit 1)
|
||||
THEN (SELECT prices_history.cost FROM prices_history WHERE prices_history.datetime <= stock_move.date AND prices_history.product_id = stock_move.product_id ORDER BY prices_history.datetime ASC limit 1)
|
||||
ELSE stock_move.price_unit
|
||||
END AS cost
|
||||
FROM
|
||||
|
|
Loading…
Reference in New Issue