[FIX] stock_account: fixed the stock valuation at date report
bzr revid: qdp-launchpad@openerp.com-20131206163307-zurim6dmg30pxnzl
This commit is contained in:
parent
eabe8af3bb
commit
3115161c29
|
@ -36,6 +36,7 @@ class wizard_valuation_history(osv.osv_memory):
|
|||
class stock_history(osv.osv):
|
||||
_name = 'stock.history'
|
||||
_auto = False
|
||||
_order = 'date asc'
|
||||
|
||||
def read_group(self, cr, uid, domain, fields, groupby, offset=0, limit=None, context=None, orderby=False):
|
||||
res = super(stock_history, self).read_group(cr, uid, domain, fields, groupby, offset=offset, limit=limit, context=context, orderby=orderby)
|
||||
|
@ -54,7 +55,7 @@ class stock_history(osv.osv):
|
|||
res = {}
|
||||
for line in self.browse(cr, uid, ids, context=context):
|
||||
if line.product_id.cost_method == 'real':
|
||||
res[line.id] = line.quantity * line.price_unit_on_move
|
||||
res[line.id] = line.quantity * line.price_unit_on_quant
|
||||
else:
|
||||
res[line.id] = line.quantity * product_obj.get_history_price(cr, uid, line.product_id.id, line.company_id.id, context=context)
|
||||
return res
|
||||
|
@ -68,7 +69,7 @@ class stock_history(osv.osv):
|
|||
'product_categ_id': fields.many2one('product.category', 'Product Category', required=True),
|
||||
'quantity': fields.integer('Quantity'),
|
||||
'date': fields.datetime('Operation Date'),
|
||||
'price_unit_on_move': fields.float('Value'),
|
||||
'price_unit_on_quant': fields.float('Value'),
|
||||
'cost_method': fields.char('Cost Method'),
|
||||
'inventory_value': fields.function(_get_inventory_value, string="Inventory Value", type='float', readonly=True),
|
||||
}
|
||||
|
@ -77,23 +78,52 @@ class stock_history(osv.osv):
|
|||
tools.drop_view_if_exists(cr, 'stock_history')
|
||||
cr.execute("""
|
||||
CREATE OR REPLACE VIEW stock_history AS (
|
||||
SELECT
|
||||
stock_move.id AS id,
|
||||
(SELECT
|
||||
quant.id AS id,
|
||||
stock_move.id AS move_id,
|
||||
stock_move.location_dest_id AS location_id,
|
||||
stock_move.product_id AS product_id,
|
||||
product_template.categ_id AS product_categ_id,
|
||||
stock_move.product_qty AS quantity,
|
||||
quant.qty AS quantity,
|
||||
stock_move.date AS date,
|
||||
ir_property.value_text AS cost_method,
|
||||
stock_move.price_unit as price_unit_on_move
|
||||
quant.cost as price_unit_on_quant
|
||||
FROM
|
||||
stock_move
|
||||
LEFT JOIN
|
||||
stock_quant quant ON quant.id IN (SELECT quant_id FROM stock_quant_move_rel WHERE move_id = stock_move.id)
|
||||
LEFT JOIN
|
||||
stock_location location ON stock_move.location_dest_id = location.id
|
||||
LEFT JOIN
|
||||
product_product ON product_product.id = stock_move.product_id
|
||||
LEFT JOIN
|
||||
product_template ON product_template.id = product_product.product_tmpl_id
|
||||
LEFT JOIN
|
||||
ir_property ON (ir_property.name = 'cost_method' and ir_property.res_id = 'product.template,' || product_template.id::text)
|
||||
WHERE stock_move.state = 'done'
|
||||
WHERE stock_move.state = 'done' AND location.usage = 'internal'
|
||||
) UNION
|
||||
(SELECT
|
||||
- quant.id AS id,
|
||||
stock_move.id AS move_id,
|
||||
stock_move.location_id AS location_id,
|
||||
stock_move.product_id AS product_id,
|
||||
product_template.categ_id AS product_categ_id,
|
||||
- quant.qty AS quantity,
|
||||
stock_move.date AS date,
|
||||
ir_property.value_text AS cost_method,
|
||||
quant.cost as price_unit_on_quant
|
||||
FROM
|
||||
stock_move
|
||||
LEFT JOIN
|
||||
stock_quant quant ON quant.id IN (SELECT quant_id FROM stock_quant_move_rel WHERE move_id = stock_move.id)
|
||||
LEFT JOIN
|
||||
stock_location location ON stock_move.location_id = location.id
|
||||
LEFT JOIN
|
||||
product_product ON product_product.id = stock_move.product_id
|
||||
LEFT JOIN
|
||||
product_template ON product_template.id = product_product.product_tmpl_id
|
||||
LEFT JOIN
|
||||
ir_property ON (ir_property.name = 'cost_method' and ir_property.res_id = 'product.template,' || product_template.id::text)
|
||||
WHERE stock_move.state = 'done' AND location.usage = 'internal'
|
||||
)
|
||||
)""")
|
||||
|
|
|
@ -61,6 +61,7 @@
|
|||
<filter string="Product" icon="terp-accessories-archiver" context="{'group_by':'product_id'}" name='group_by_product'/>
|
||||
<filter string="Product Category" icon="terp-accessories-archiver" context="{'group_by':'product_categ_id'}"/>
|
||||
<filter string="Location" icon="terp-accessories-archiver" context="{'group_by':'location_id'}"/>
|
||||
<filter string="Move" icon="terp-accessories-archiver" context="{'group_by':'move_id'}"/>
|
||||
<filter string="Company" icon="terp-go-home" context="{'group_by':'company_id'}" groups="base.group_multi_company"/>
|
||||
</group>
|
||||
</search>
|
||||
|
|
Loading…
Reference in New Issue