From 59a3934f59e9d71b693b75b717dec093b85cab8b Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Tue, 10 Nov 2015 21:36:50 +0100 Subject: [PATCH] [IMP] intrastat_base: A lot of imps: * Add product_origin_country_id on declaration/computation lines Copy incoterms and destination country from SO to invoice when invoicing from SO We need weight even when supplementary units is used Small cleanups and enhancements * Add support for accessory costs Add default values for intrastat transaction on company Code cleanup * If rounded weight is 0, put 1 Take into account the taxes for B2C Small code cleanup * Remove field exclude_from_intrastat Re-organise view of intrastat.product.declaration * Add option intrastat_accessory_costs on company Set more fields as invisible (localisation should put them visible if they need it) Fix handling of suppl. units when hs_code is empty on invoice line (but set on product) Small usability enhancements * Warning -> UserError * Inspired by the PR https://github.com/akretion/account-financial-reporting/pull/8 of Luc de Meyer * total_amount is a sum of integers, so it should be an integer Add transport mode in computation tree view * Demo VAT number should be on EU customers --- intrastat_base/__openerp__.py | 2 +- intrastat_base/demo/intrastat_demo.xml | 2 +- intrastat_base/models/__init__.py | 22 +------------- intrastat_base/models/account_tax.py | 2 +- intrastat_base/models/intrastat_common.py | 35 ++++++----------------- intrastat_base/models/product_template.py | 8 +----- intrastat_base/models/res_company.py | 2 +- intrastat_base/models/res_country.py | 2 +- intrastat_base/views/account_tax.xml | 5 ++-- intrastat_base/views/intrastat.xml | 2 +- intrastat_base/views/product_template.xml | 4 +-- 11 files changed, 22 insertions(+), 64 deletions(-) diff --git a/intrastat_base/__openerp__.py b/intrastat_base/__openerp__.py index f50f146..a9e92b0 100644 --- a/intrastat_base/__openerp__.py +++ b/intrastat_base/__openerp__.py @@ -1,4 +1,4 @@ -# -*- encoding: utf-8 -*- +# -*- coding: utf-8 -*- ############################################################################## # # Intrastat base module for Odoo diff --git a/intrastat_base/demo/intrastat_demo.xml b/intrastat_base/demo/intrastat_demo.xml index 953d92b..422afa8 100644 --- a/intrastat_base/demo/intrastat_demo.xml +++ b/intrastat_base/demo/intrastat_demo.xml @@ -18,7 +18,7 @@ True - + BE0443167858 True diff --git a/intrastat_base/models/__init__.py b/intrastat_base/models/__init__.py index 18530f9..a571f6a 100644 --- a/intrastat_base/models/__init__.py +++ b/intrastat_base/models/__init__.py @@ -1,24 +1,4 @@ -# -*- encoding: utf-8 -*- -############################################################################## -# -# Report intrastat base module for Odoo -# Copyright (C) 2011-2014 Akretion (http://www.akretion.com) -# @author Alexis de Lattre -# -# This program is free software: you can redistribute it and/or modify -# 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 Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## +# -*- coding: utf-8 -*- from . import res_country from . import product_template diff --git a/intrastat_base/models/account_tax.py b/intrastat_base/models/account_tax.py index 197e51d..e11db59 100644 --- a/intrastat_base/models/account_tax.py +++ b/intrastat_base/models/account_tax.py @@ -1,4 +1,4 @@ -# -*- encoding: utf-8 -*- +# -*- coding: utf-8 -*- ############################################################################## # # Intrastat base module for Odoo diff --git a/intrastat_base/models/intrastat_common.py b/intrastat_base/models/intrastat_common.py index ae892c0..3d44b7c 100644 --- a/intrastat_base/models/intrastat_common.py +++ b/intrastat_base/models/intrastat_common.py @@ -1,4 +1,4 @@ -# -*- encoding: utf-8 -*- +# -*- coding: utf-8 -*- ############################################################################## # # Intrastat base module for Odoo @@ -21,8 +21,7 @@ ############################################################################## from openerp import models, fields, api, tools, _ -from openerp.exceptions import Warning, ValidationError -from dateutil.relativedelta import relativedelta +from openerp.exceptions import Warning as UserError import logging logger = logging.getLogger(__name__) @@ -36,7 +35,7 @@ class IntrastatCommon(models.AbstractModel): @api.one @api.depends('declaration_line_ids.amount_company_currency') def _compute_numbers(self): - total_amount = 0.0 + total_amount = 0 # it is an integer num_lines = 0 for line in self.declaration_line_ids: total_amount += line.amount_company_currency @@ -44,34 +43,18 @@ class IntrastatCommon(models.AbstractModel): self.num_decl_lines = num_lines self.total_amount = total_amount - @api.one - @api.depends('start_date') - def _compute_dates(self): - start_date_dt = fields.Date.from_string(self.start_date) - self.end_date = fields.Date.to_string( - start_date_dt + relativedelta(day=31)) - self.year_month = start_date_dt.strftime('%Y-%m') - - @api.one - def _check_start_date(self): - '''Check that the start date is the first day of the month''' - datetime_to_check = fields.Date.from_string(self.start_date) - if datetime_to_check.day != 1: - raise ValidationError( - _('The start date must be the first day of the month')) - @api.one def _check_generate_lines(self): """Check wether all requirements are met for generating lines.""" if not self.company_id: - raise Warning(_("Company not yet set on intrastat report.")) + raise UserError(_("Company not yet set on intrastat report.")) company_obj = self.company_id if not company_obj.country_id: - raise Warning( + raise UserError( _("The country is not set on the company '%s'.") % company_obj.name) if company_obj.currency_id.name != 'EUR': - raise Warning( + raise UserError( _("The company currency must be 'EUR', but is currently '%s'.") % company_obj.currency_id.name) return True @@ -79,7 +62,7 @@ class IntrastatCommon(models.AbstractModel): @api.one def _check_generate_xml(self): if not self.company_id.partner_id.vat: - raise Warning( + raise UserError( _("The VAT number is not set for the partner '%s'.") % self.company_id.partner_id.name) return True @@ -102,7 +85,7 @@ class IntrastatCommon(models.AbstractModel): "The XML file is invalid against the XML Schema Definition") logger.warning(xml_string) logger.warning(e) - raise Warning( + raise UserError( _("The generated XML file is not valid against the official " "XML Schema Definition. The generated XML file and the " "full error have been written in the server logs. " @@ -181,7 +164,7 @@ class IntrastatCommon(models.AbstractModel): def unlink(self): for intrastat in self: if intrastat.state == 'done': - raise Warning( + raise UserError( _('Cannot delete the declaration %s ' 'because it is in Done state') % self.year_month) return super(IntrastatCommon, self).unlink() diff --git a/intrastat_base/models/product_template.py b/intrastat_base/models/product_template.py index 5373cb3..30132bc 100644 --- a/intrastat_base/models/product_template.py +++ b/intrastat_base/models/product_template.py @@ -1,4 +1,4 @@ -# -*- encoding: utf-8 -*- +# -*- coding: utf-8 -*- ############################################################################## # # Intrastat base module for Odoo @@ -27,12 +27,6 @@ from openerp.exceptions import ValidationError class ProductTemplate(models.Model): _inherit = "product.template" - exclude_from_intrastat = fields.Boolean( - string='Exclude from Intrastat reports', - help="If set to True, the product or service will not be " - "taken into account for Intrastat Product or Service reports. " - "So you should leave this field to False unless you have a " - "very good reason.") is_accessory_cost = fields.Boolean( string='Is accessory cost', help="Activate this option for shipping costs, packaging " diff --git a/intrastat_base/models/res_company.py b/intrastat_base/models/res_company.py index 2206c76..1175d76 100644 --- a/intrastat_base/models/res_company.py +++ b/intrastat_base/models/res_company.py @@ -1,4 +1,4 @@ -# -*- encoding: utf-8 -*- +# -*- coding: utf-8 -*- ############################################################################## # # Intrastat base module for Odoo diff --git a/intrastat_base/models/res_country.py b/intrastat_base/models/res_country.py index 7a34e77..8703f10 100644 --- a/intrastat_base/models/res_country.py +++ b/intrastat_base/models/res_country.py @@ -1,4 +1,4 @@ -# -*- encoding: utf-8 -*- +# -*- coding: utf-8 -*- ############################################################################## # # Intrastat base module for Odoo diff --git a/intrastat_base/views/account_tax.xml b/intrastat_base/views/account_tax.xml index 5defe29..1e91bb5 100644 --- a/intrastat_base/views/account_tax.xml +++ b/intrastat_base/views/account_tax.xml @@ -1,7 +1,7 @@ @@ -16,7 +16,8 @@ - + + diff --git a/intrastat_base/views/intrastat.xml b/intrastat_base/views/intrastat.xml index 7b4cdf7..73762d0 100644 --- a/intrastat_base/views/intrastat.xml +++ b/intrastat_base/views/intrastat.xml @@ -11,7 +11,7 @@ diff --git a/intrastat_base/views/product_template.xml b/intrastat_base/views/product_template.xml index dc61ca5..1f4f73f 100644 --- a/intrastat_base/views/product_template.xml +++ b/intrastat_base/views/product_template.xml @@ -16,9 +16,9 @@ - + attrs="{'invisible': [('type', '!=', 'service')]}" + invisible="1"/>