[IMP] Change standard_price field of product into a property: requires changing SQL queries
bzr revid: jco@openerp.com-20130417150213-4nm9tc8nzvsgm5ix
This commit is contained in:
@@ -72,11 +72,11 @@ class report_mrp_inout(osv.osv):
|
||||
min(sm.id) as id,
|
||||
to_char(sm.date,'YYYY:IW') as date,
|
||||
sum(case when (sl.usage='internal') then
|
||||
pt.standard_price * sm.product_qty
|
||||
ip.value_float * sm.product_qty
|
||||
else
|
||||
0.0
|
||||
end - case when (sl2.usage='internal') then
|
||||
pt.standard_price * sm.product_qty
|
||||
ip.value_float * sm.product_qty
|
||||
else
|
||||
0.0
|
||||
end) as value
|
||||
@@ -86,6 +86,8 @@ class report_mrp_inout(osv.osv):
|
||||
on (pp.id = sm.product_id)
|
||||
left join product_template pt
|
||||
on (pt.id = pp.product_tmpl_id)
|
||||
LEFT JOIN ir_property ip
|
||||
ON (ip.name='standard_price' AND ip.res_id=CONCAT('product.template,',pt.id) AND ip.company_id=sm.company_id)
|
||||
left join stock_location sl
|
||||
on ( sl.id = sm.location_id)
|
||||
left join stock_location sl2
|
||||
|
||||
@@ -163,22 +163,23 @@ class report_sales_by_margin_pos(osv.osv):
|
||||
pt.name as product_name,
|
||||
to_char(date_trunc('day',po.date_order),'YYYY-MM-DD')::text as date_order,
|
||||
sum(pol.qty) as qty,
|
||||
pt.list_price-pt.standard_price as net_margin_per_qty,
|
||||
(pt.list_price-pt.standard_price) *sum(pol.qty) as total
|
||||
pt.list_price-ip.value_float as net_margin_per_qty,
|
||||
(pt.list_price-ip.value_float) *sum(pol.qty) as total
|
||||
from
|
||||
product_template as pt,
|
||||
product_product as pp,
|
||||
ir_property as ip,
|
||||
pos_order_line as pol,
|
||||
pos_order as po
|
||||
where
|
||||
pol.product_id = pp.product_tmpl_id and
|
||||
pp.product_tmpl_id = pt.id and
|
||||
po.id = pol.order_id
|
||||
|
||||
po.id = pol.order_id and
|
||||
ip.name='standard_price' AND ip.res_id=CONCAT('product.template,',pt.id) AND ip.company_id=po.company_id
|
||||
group by
|
||||
pt.name,
|
||||
pt.list_price,
|
||||
pt.standard_price,
|
||||
ip.value_float,
|
||||
po.user_id,
|
||||
to_char(date_trunc('day',po.date_order),'YYYY-MM-DD')::text
|
||||
|
||||
@@ -208,22 +209,23 @@ class report_sales_by_margin_pos_month(osv.osv):
|
||||
pt.name as product_name,
|
||||
to_char(date_trunc('month',po.date_order),'YYYY-MM-DD')::text as date_order,
|
||||
sum(pol.qty) as qty,
|
||||
pt.list_price-pt.standard_price as net_margin_per_qty,
|
||||
(pt.list_price-pt.standard_price) *sum(pol.qty) as total
|
||||
pt.list_price-ip.value_float as net_margin_per_qty,
|
||||
(pt.list_price-ip.value_float) *sum(pol.qty) as total
|
||||
from
|
||||
product_template as pt,
|
||||
ir_property as ip,
|
||||
product_product as pp,
|
||||
pos_order_line as pol,
|
||||
pos_order as po
|
||||
where
|
||||
pol.product_id = pp.product_tmpl_id and
|
||||
pp.product_tmpl_id = pt.id and
|
||||
po.id = pol.order_id
|
||||
|
||||
po.id = pol.order_id and
|
||||
ip.name='standard_price' AND ip.res_id=CONCAT('product.template,',pt.id) AND ip.company_id=po.company_id
|
||||
group by
|
||||
pt.name,
|
||||
pt.list_price,
|
||||
pt.standard_price,
|
||||
ip.value_float,
|
||||
po.user_id,
|
||||
to_char(date_trunc('month',po.date_order),'YYYY-MM-DD')::text
|
||||
|
||||
|
||||
@@ -300,7 +300,10 @@ class product_template(osv.osv):
|
||||
'rental': fields.boolean('Can be Rent'),
|
||||
'categ_id': fields.many2one('product.category','Category', required=True, change_default=True, domain="[('type','=','normal')]" ,help="Select category for the current product"),
|
||||
'list_price': fields.float('Sale Price', digits_compute=dp.get_precision('Product Price'), help="Base price to compute the customer price. Sometimes called the catalog price."),
|
||||
'standard_price': fields.float('Cost', digits_compute=dp.get_precision('Product Price'), help="Cost price of the product used for standard stock valuation in accounting and used as a base price on purchase orders.", groups="base.group_user"),
|
||||
'standard_price': fields.property('product.template', type = 'float',
|
||||
help="Cost price of the product used for standard stock valuation in accounting and used as a base price on purchase orders.",
|
||||
groups="base.group_user"),
|
||||
#fields.float('Cost', digits_compute=dp.get_precision('Product Price'), help="Cost price of the product used for standard stock valuation in accounting and used as a base price on purchase orders.", groups="base.group_user"),
|
||||
'volume': fields.float('Volume', help="The volume in m3."),
|
||||
'weight': fields.float('Gross Weight', digits_compute=dp.get_precision('Stock Weight'), help="The gross weight in Kg."),
|
||||
'weight_net': fields.float('Net Weight', digits_compute=dp.get_precision('Stock Weight'), help="The net weight in Kg."),
|
||||
@@ -323,6 +326,7 @@ class product_template(osv.osv):
|
||||
'mes_type': fields.selection((('fixed', 'Fixed'), ('variable', 'Variable')), 'Measure Type'),
|
||||
'seller_ids': fields.one2many('product.supplierinfo', 'product_id', 'Supplier'),
|
||||
'company_id': fields.many2one('res.company', 'Company', select=1),
|
||||
|
||||
}
|
||||
|
||||
def _get_uom_id(self, cr, uid, *args):
|
||||
|
||||
@@ -57,11 +57,13 @@ class product_product(osv.osv):
|
||||
sum(l.quantity) as num_qty,
|
||||
sum(l.quantity * (l.price_subtotal/l.quantity)) as total,
|
||||
sum(l.quantity * pt.list_price) as sale_expected,
|
||||
sum(l.quantity * pt.standard_price) as normal_cost
|
||||
sum(l.quantity * ip.value_float) as normal_cost
|
||||
from account_invoice_line l
|
||||
left join account_invoice i on (l.invoice_id = i.id)
|
||||
left join product_product product on (product.id=l.product_id)
|
||||
left join product_template pt on (pt.id=product.product_tmpl_id)
|
||||
left join ir_property ip
|
||||
on (ip.name='standard_price' AND ip.res_id=CONCAT('product.template,',pt.id) AND ip.company_id=i.company_id)
|
||||
where l.product_id = %s and i.state in %s and i.type IN %s and (i.date_invoice IS NULL or (i.date_invoice>=%s and i.date_invoice<=%s))
|
||||
"""
|
||||
invoice_types = ('out_invoice', 'in_refund')
|
||||
|
||||
@@ -95,14 +95,14 @@ class purchase_report(osv.osv):
|
||||
extract(epoch from age(l.date_planned,s.date_order))/(24*60*60)::decimal(16,2) as delay_pass,
|
||||
count(*) as nbr,
|
||||
(l.price_unit*l.product_qty)::decimal(16,2) as price_total,
|
||||
avg(100.0 * (l.price_unit*l.product_qty) / NULLIF(t.standard_price*l.product_qty/u.factor*u2.factor, 0.0))::decimal(16,2) as negociation,
|
||||
|
||||
sum(t.standard_price*l.product_qty/u.factor*u2.factor)::decimal(16,2) as price_standard,
|
||||
avg(100.0 * (l.price_unit*l.product_qty) / NULLIF(ip.value_float*l.product_qty/u.factor*u2.factor, 0.0))::decimal(16,2) as negociation,
|
||||
sum(ip.value_float*l.product_qty/u.factor*u2.factor)::decimal(16,2) as price_standard,
|
||||
(sum(l.product_qty*l.price_unit)/NULLIF(sum(l.product_qty/u.factor*u2.factor),0.0))::decimal(16,2) as price_average
|
||||
from purchase_order s
|
||||
left join purchase_order_line l on (s.id=l.order_id)
|
||||
left join product_product p on (l.product_id=p.id)
|
||||
left join product_template t on (p.product_tmpl_id=t.id)
|
||||
LEFT JOIN ir_property ip ON (ip.name='standard_price' AND ip.res_id=CONCAT('product.template,',t.id) AND ip.company_id=s.company_id)
|
||||
left join product_uom u on (u.id=l.product_uom)
|
||||
left join product_uom u2 on (u2.id=t.uom_id)
|
||||
where l.product_id is not null
|
||||
|
||||
@@ -94,11 +94,11 @@ class report_stock_move(osv.osv):
|
||||
ELSE 0.0
|
||||
END AS in_qty,
|
||||
CASE WHEN sp.type in ('out') THEN
|
||||
sum(sm.product_qty * pu.factor / pu2.factor) * pt.standard_price
|
||||
sum(sm.product_qty * pu.factor / pu2.factor) * ip.value_float
|
||||
ELSE 0.0
|
||||
END AS out_value,
|
||||
CASE WHEN sp.type in ('in') THEN
|
||||
sum(sm.product_qty * pu.factor / pu2.factor) * pt.standard_price
|
||||
sum(sm.product_qty * pu.factor / pu2.factor) * ip.value_float
|
||||
ELSE 0.0
|
||||
END AS in_value,
|
||||
min(sm.id) as sm_id,
|
||||
@@ -128,10 +128,11 @@ class report_stock_move(osv.osv):
|
||||
LEFT JOIN product_uom pu ON (sm.product_uom=pu.id)
|
||||
LEFT JOIN product_uom pu2 ON (sm.product_uom=pu2.id)
|
||||
LEFT JOIN product_template pt ON (pp.product_tmpl_id=pt.id)
|
||||
LEFT JOIN ir_property ip ON (ip.name='standard_price' AND ip.res_id=CONCAT('product.template,',pt.id) AND ip.company_id=sm.company_id)
|
||||
GROUP BY
|
||||
sm.id,sp.type, sm.date,sm.partner_id,
|
||||
sm.product_id,sm.state,sm.product_uom,sm.date_expected,
|
||||
sm.product_id,pt.standard_price, sm.picking_id, sm.product_qty,
|
||||
sm.product_id,ip.value_float, sm.picking_id, sm.product_qty,
|
||||
sm.company_id,sm.product_qty, sm.location_id,sm.location_dest_id,pu.factor,pt.categ_id, sp.stock_journal_id)
|
||||
AS al
|
||||
GROUP BY
|
||||
@@ -181,13 +182,14 @@ CREATE OR REPLACE view report_stock_inventory AS (
|
||||
m.company_id,
|
||||
m.state as state, m.prodlot_id as prodlot_id,
|
||||
|
||||
coalesce(sum(-pt.standard_price * m.product_qty * pu.factor / pu2.factor)::decimal, 0.0) as value,
|
||||
coalesce(sum(-ip.value_float * m.product_qty * pu.factor / pu2.factor)::decimal, 0.0) as value,
|
||||
coalesce(sum(-m.product_qty * pu.factor / pu2.factor)::decimal, 0.0) as product_qty
|
||||
FROM
|
||||
stock_move m
|
||||
LEFT JOIN stock_picking p ON (m.picking_id=p.id)
|
||||
LEFT JOIN product_product pp ON (m.product_id=pp.id)
|
||||
LEFT JOIN product_template pt ON (pp.product_tmpl_id=pt.id)
|
||||
LEFT JOIN ir_property ip ON (ip.name='standard_price' AND ip.res_id=CONCAT('product.template,',pt.id) AND ip.company_id=m.company_id)
|
||||
LEFT JOIN product_uom pu ON (pt.uom_id=pu.id)
|
||||
LEFT JOIN product_uom pu2 ON (m.product_uom=pu2.id)
|
||||
LEFT JOIN product_uom u ON (m.product_uom=u.id)
|
||||
@@ -205,13 +207,14 @@ CREATE OR REPLACE view report_stock_inventory AS (
|
||||
m.product_id as product_id, pt.categ_id as product_categ_id, l.usage as location_type, l.scrap_location as scrap_location,
|
||||
m.company_id,
|
||||
m.state as state, m.prodlot_id as prodlot_id,
|
||||
coalesce(sum(pt.standard_price * m.product_qty * pu.factor / pu2.factor)::decimal, 0.0) as value,
|
||||
coalesce(sum(ip.value_float * m.product_qty * pu.factor / pu2.factor)::decimal, 0.0) as value,
|
||||
coalesce(sum(m.product_qty * pu.factor / pu2.factor)::decimal, 0.0) as product_qty
|
||||
FROM
|
||||
stock_move m
|
||||
LEFT JOIN stock_picking p ON (m.picking_id=p.id)
|
||||
LEFT JOIN product_product pp ON (m.product_id=pp.id)
|
||||
LEFT JOIN product_template pt ON (pp.product_tmpl_id=pt.id)
|
||||
LEFT JOIN ir_property ip ON (ip.name='standard_price' AND ip.res_id=CONCAT('product.template,',pt.id) AND ip.company_id=m.company_id)
|
||||
LEFT JOIN product_uom pu ON (pt.uom_id=pu.id)
|
||||
LEFT JOIN product_uom pu2 ON (m.product_uom=pu2.id)
|
||||
LEFT JOIN product_uom u ON (m.product_uom=u.id)
|
||||
|
||||
Reference in New Issue
Block a user