mirror of
https://github.com/OCA/intrastat-extrastat.git
synced 2025-02-16 17:13:41 +02:00
[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
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user