diff --git a/addons/report_intrastat/report_intrastat.py b/addons/report_intrastat/report_intrastat.py index 79057ca0f45..3a420d150a6 100644 --- a/addons/report_intrastat/report_intrastat.py +++ b/addons/report_intrastat/report_intrastat.py @@ -67,7 +67,8 @@ class report_intrastat(osv.osv): 'intrastat_id': fields.many2one('report.intrastat.code', 'Intrastat code', readonly=True), 'weight': fields.float('Weight', readonly=True), 'value': fields.float('Value', readonly=True), - 'type': fields.selection([('import', 'Import'), ('export', 'Export')], 'Type') + 'type': fields.selection([('import', 'Import'), ('export', 'Export')], 'Type'), + 'currency_id': fields.many2one('res.currency', "Currency", readonly=True), } def init(self, cr): cr.execute(""" @@ -76,7 +77,7 @@ class report_intrastat(osv.osv): substring(m.create_date for 7)||'-01' as name, min(m.id) as id, pt.intrastat_id as intrastat_id, - case when l.usage in ('supplier', 'customer') then pc.code else c.code end as code, + case when l.usage in ('supplier', 'customer') then upper(pc.code) else upper(c.code) end as code, sum(case when pol.price_unit is not null then pol.price_unit * m.product_qty else @@ -86,7 +87,11 @@ class report_intrastat(osv.osv): end end) as value, sum(pt.weight_net * m.product_qty) as weight, - case when l.usage in ('supplier', 'customer') then 'import' else 'export' end as type + case when l.usage in ('supplier', 'customer') then 'import' else 'export' end as type, + case when ppl.currency_id is not null + then ppl.currency_id + else spl.currency_id + end as currency_id from stock_move m left join (product_template pt @@ -102,14 +107,22 @@ class report_intrastat(osv.osv): on (sp.id = m.picking_id) left join stock_location l on (l.id = m.location_id) left join stock_location dl on (dl.id = m.location_dest_id) - left join purchase_order_line pol on (pol.id = m.purchase_line_id) - left join sale_order_line sol on (sol.id = m.sale_line_id) + left join (purchase_order_line pol + left join (purchase_order po + left join product_pricelist ppl on (ppl.id = po.pricelist_id)) + on (po.id = pol.order_id)) + on (pol.id = m.purchase_line_id) + left join (sale_order_line sol + left join (sale_order so + left join product_pricelist spl on (spl.id = so.pricelist_id)) + on (so.id = sol.order_id)) + on (sol.id = m.sale_line_id) where m.state != 'draft' and ((l.usage in ('supplier', 'customer') and dl.usage not in ('supplier', 'customer')) or (dl.usage in ('supplier', 'customer') and l.usage not in ('supplier', 'customer'))) and (c.intrastat is not null or pc.intrastat is not null) - group by substring(m.create_date for 7), pt.intrastat_id, c.code, pc.code, l.usage, dl.usage - )""") + group by substring(m.create_date for 7), pt.intrastat_id, c.code, pc.code, l.usage, dl.usage, ppl.currency_id, spl.currency_id + )""") report_intrastat() diff --git a/addons/report_intrastat/report_intrastat_view.xml b/addons/report_intrastat/report_intrastat_view.xml index 3296092174a..3cf1781c0a3 100644 --- a/addons/report_intrastat/report_intrastat_view.xml +++ b/addons/report_intrastat/report_intrastat_view.xml @@ -81,6 +81,7 @@ +