Launchpad automatic translations update.
[odoo/odoo.git] / addons / report_intrastat / report_intrastat.py
index e9387c0..a77c4f5 100644 (file)
@@ -1,27 +1,27 @@
-# -*- encoding: utf-8 -*-
+# -*- coding: utf-8 -*-
 ##############################################################################
 #
 #    OpenERP, Open Source Management Solution
-#    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
-#    $Id$
+#    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
 #
 #    This program is free software: you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation, either version 3 of the License, or
-#    (at your option) any later version.
+#    it under the terms of the GNU Affero General Public License as
+#    published by the Free Software Foundation, either version 3 of the
+#    License, or (at your option) any later version.
 #
 #    This program is distributed in the hope that it will be useful,
 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
+#    GNU Affero General Public License for more details.
 #
-#    You should have received a copy of the GNU General Public License
+#    You should have received a copy of the GNU Affero General Public License
 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
 ##############################################################################
 
 from osv import osv, fields
 from tools.sql import drop_view_if_exists
+from decimal_precision import decimal_precision as dp
 
 
 class res_country(osv.osv):
@@ -33,8 +33,10 @@ class res_country(osv.osv):
     _defaults = {
         'intrastat': lambda *a: False,
     }
+
 res_country()
 
+
 class report_intrastat_code(osv.osv):
     _name = "report.intrastat.code"
     _description = "Intrastat code"
@@ -42,14 +44,17 @@ class report_intrastat_code(osv.osv):
         'name': fields.char('Intrastat Code', size=16),
         'description': fields.char('Description', size=64),
     }
+
 report_intrastat_code()
 
+
 class product_template(osv.osv):
     _name = "product.template"
     _inherit = "product.template"
     _columns = {
         'intrastat_id': fields.many2one('report.intrastat.code', 'Intrastat code'),
     }
+
 product_template()
 
 class report_intrastat(osv.osv):
@@ -57,13 +62,15 @@ class report_intrastat(osv.osv):
     _description = "Intrastat report"
     _auto = False
     _columns = {
-        'name': fields.many2one('account.period', 'Period', readonly=True,select=True),
+        'name': fields.char('Year',size=64,required=False, readonly=True),
+        'month':fields.selection([('01','January'), ('02','February'), ('03','March'), ('04','April'), ('05','May'), ('06','June'),
+                                  ('07','July'), ('08','August'), ('09','September'), ('10','October'), ('11','November'), ('12','December')],'Month',readonly=True),
         'supply_units':fields.float('Supply Units', readonly=True),
-        'ref':fields.char('Origin',size=64, readonly=True),
-        'code': fields.char('Country code', size="2", readonly=True),
+        'ref':fields.char('Source document',size=64, readonly=True),
+        'code': fields.char('Country code', size=2, readonly=True),
         'intrastat_id': fields.many2one('report.intrastat.code', 'Intrastat code', readonly=True),
         'weight': fields.float('Weight', readonly=True),
-        'value': fields.float('Value', readonly=True),
+        'value': fields.float('Value', readonly=True, digits_compute=dp.get_precision('Account')),
         'type': fields.selection([('import', 'Import'), ('export', 'Export')], 'Type'),
         'currency_id': fields.many2one('res.currency', "Currency", readonly=True),
     }
@@ -72,7 +79,8 @@ class report_intrastat(osv.osv):
         cr.execute("""
             create or replace view report_intrastat as (
                 select
-                    inv.period_id as name,
+                    to_char(inv.create_date, 'YYYY') as name,
+                    to_char(inv.create_date, 'MM') as month,
                     min(inv_line.id) as id,
                     intrastat.id as intrastat_id,
                     upper(inv_country.code) as code,
@@ -81,26 +89,12 @@ class report_intrastat(osv.osv):
                             else 0
                         end) as value,
                     sum(
-                        case when uom.category_id != puom.category_id then pt.weight_net * inv_line.quantity
-                        else
-                            case when uom.factor_inv_data > 0
-                                then
-                                    pt.weight_net * inv_line.quantity * uom.factor_inv_data
-                                else
-                                    pt.weight_net * inv_line.quantity / uom.factor
-                            end
-                        end
+                        case when uom.category_id != puom.category_id then (pt.weight_net * inv_line.quantity)
+                        else (pt.weight_net * inv_line.quantity * uom.factor) end
                     ) as weight,
                     sum(
                         case when uom.category_id != puom.category_id then inv_line.quantity
-                        else
-                            case when uom.factor_inv_data > 0
-                                then
-                                    inv_line.quantity * uom.factor_inv_data
-                                else
-                                    inv_line.quantity / uom.factor
-                            end
-                        end
+                        else (inv_line.quantity * uom.factor) end
                     ) as supply_units,
 
                     inv.currency_id as currency_id,
@@ -114,7 +108,7 @@ class report_intrastat(osv.osv):
                     left join account_invoice_line inv_line on inv_line.invoice_id=inv.id
                     left join (product_template pt
                         left join product_product pp on (pp.product_tmpl_id = pt.id))
-                    on (inv_line.product_id = pt.id)
+                    on (inv_line.product_id = pp.id)
                     left join product_uom uom on uom.id=inv_line.uos_id
                     left join product_uom puom on puom.id = pt.uom_id
                     left join report_intrastat_code intrastat on pt.intrastat_id = intrastat.id
@@ -126,10 +120,7 @@ class report_intrastat(osv.osv):
                     inv.state in ('open','paid')
                     and inv_line.product_id is not null
                     and inv_country.intrastat=true
-                group by inv.period_id,intrastat.id,inv.type,pt.intrastat_id, inv_country.code,inv.number,  inv.currency_id
+                group by to_char(inv.create_date, 'YYYY'), to_char(inv.create_date, 'MM'),intrastat.id,inv.type,pt.intrastat_id, inv_country.code,inv.number,  inv.currency_id
             )""")
-report_intrastat()
-
-
-# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
 
+report_intrastat()