diff --git a/intrastat_base/demo/intrastat_demo.xml b/intrastat_base/demo/intrastat_demo.xml index d5354c1..f8adbb7 100644 --- a/intrastat_base/demo/intrastat_demo.xml +++ b/intrastat_base/demo/intrastat_demo.xml @@ -17,7 +17,7 @@ Shipping costs - SHIP + SHIP_S service 30 diff --git a/intrastat_product/__manifest__.py b/intrastat_product/__manifest__.py index 1c8572c..92dedc1 100644 --- a/intrastat_product/__manifest__.py +++ b/intrastat_product/__manifest__.py @@ -6,37 +6,36 @@ # @author Kumar Aberer { - 'name': 'Intrastat Product', - 'version': '12.0.1.0.0', - 'category': 'Intrastat', - 'license': 'AGPL-3', - 'summary': 'Base module for Intrastat Product', - 'author': 'brain-tec AG, Akretion, Noviat, ' - 'Odoo Community Association (OCA)', - 'depends': [ - 'intrastat_base', - 'product_harmonized_system', - 'sale_stock', - 'purchase_stock', - 'report_xlsx_helper', + "name": "Intrastat Product", + "version": "13.0.1.0.0", + "category": "Intrastat", + "license": "AGPL-3", + "summary": "Base module for Intrastat Product", + "author": "brain-tec AG, Akretion, Noviat, " "Odoo Community Association (OCA)", + "depends": [ + "intrastat_base", + "product_harmonized_system", + "sale_stock", + "purchase_stock", + "report_xlsx_helper", ], - 'excludes': ['account_intrastat'], - 'data': [ - 'views/hs_code.xml', - 'views/intrastat_region.xml', - 'views/intrastat_unit.xml', - 'views/intrastat_transaction.xml', - 'views/intrastat_transport_mode.xml', - 'views/intrastat_product_declaration.xml', - 'views/res_config_settings.xml', - 'views/account_invoice.xml', - 'views/sale_order.xml', - 'views/stock_warehouse.xml', - 'security/intrastat_security.xml', - 'security/ir.model.access.csv', - 'data/intrastat_transport_mode.xml', - 'data/intrastat_unit.xml', + "excludes": ["account_intrastat"], + "data": [ + "views/hs_code.xml", + "views/intrastat_region.xml", + "views/intrastat_unit.xml", + "views/intrastat_transaction.xml", + "views/intrastat_transport_mode.xml", + "views/intrastat_product_declaration.xml", + "views/res_config_settings.xml", + "views/account_move.xml", + "views/sale_order.xml", + "views/stock_warehouse.xml", + "security/intrastat_security.xml", + "security/ir.model.access.csv", + "data/intrastat_transport_mode.xml", + "data/intrastat_unit.xml", ], - 'demo': ['demo/intrastat_demo.xml'], - 'installable': True, + "demo": ["demo/intrastat_demo.xml"], + "installable": True, } diff --git a/intrastat_product/models/__init__.py b/intrastat_product/models/__init__.py index d2a0fdc..f2e2317 100644 --- a/intrastat_product/models/__init__.py +++ b/intrastat_product/models/__init__.py @@ -1,6 +1,6 @@ from . import res_company from . import res_config_settings -from . import account_invoice +from . import account_move from . import hs_code from . import intrastat_product_declaration from . import intrastat_region diff --git a/intrastat_product/models/account_invoice.py b/intrastat_product/models/account_move.py similarity index 51% rename from intrastat_product/models/account_invoice.py rename to intrastat_product/models/account_move.py index fae95be..e84b841 100644 --- a/intrastat_product/models/account_invoice.py +++ b/intrastat_product/models/account_move.py @@ -6,44 +6,51 @@ from odoo import api, fields, models -class AccountInvoice(models.Model): - _inherit = 'account.invoice' +class AccountMove(models.Model): + _inherit = "account.move" intrastat_transaction_id = fields.Many2one( - comodel_name='intrastat.transaction', - string='Intrastat Transaction Type', - ondelete='restrict', track_visibility='onchange', - help="Intrastat nature of transaction") + comodel_name="intrastat.transaction", + string="Intrastat Transaction Type", + ondelete="restrict", + track_visibility="onchange", + help="Intrastat nature of transaction", + ) intrastat_transport_id = fields.Many2one( - comodel_name='intrastat.transport_mode', - string='Intrastat Transport Mode', - ondelete='restrict') + comodel_name="intrastat.transport_mode", + string="Intrastat Transport Mode", + ondelete="restrict", + ) src_dest_country_id = fields.Many2one( - comodel_name='res.country', - string='Origin/Destination Country', - compute='_compute_intrastat_country', - store=True, compute_sudo=True, - help="Destination country for dispatches. Origin country for " - "arrivals.") + comodel_name="res.country", + string="Origin/Destination Country", + compute="_compute_intrastat_country", + store=True, + compute_sudo=True, + help="Destination country for dispatches. Origin country for " "arrivals.", + ) intrastat_country = fields.Boolean( - compute='_compute_intrastat_country', string='Intrastat Country', - store=True, compute_sudo=True) + compute="_compute_intrastat_country", + string="Intrastat Country", + store=True, + compute_sudo=True, + ) src_dest_region_id = fields.Many2one( - comodel_name='intrastat.region', - string='Origin/Destination Region', + comodel_name="intrastat.region", + string="Origin/Destination Region", default=lambda self: self._default_src_dest_region_id(), help="Origin region for dispatches, destination region for " "arrivals. This field is used for the Intrastat Declaration.", - ondelete='restrict') + ondelete="restrict", + ) intrastat = fields.Char( - string='Intrastat Declaration', - related='company_id.intrastat') + string="Intrastat Declaration", related="company_id.intrastat" + ) - @api.depends('partner_shipping_id.country_id', 'partner_id.country_id') + @api.depends("partner_shipping_id.country_id", "partner_id.country_id") def _compute_intrastat_country(self): for inv in self: - country = inv.partner_shipping_id.country_id\ - or inv.partner_id.country_id + country = inv.partner_shipping_id.country_id or inv.partner_id.country_id if not country: country = inv.company_id.country_id inv.src_dest_country_id = country.id @@ -51,19 +58,19 @@ class AccountInvoice(models.Model): @api.model def _default_src_dest_region_id(self): - rco = self.env['res.company'] + rco = self.env["res.company"] company = rco._company_default_get() return company.intrastat_region_id -class AccountInvoiceLine(models.Model): - _inherit = 'account.invoice.line' +class AccountMoveLine(models.Model): + _inherit = "account.move.line" hs_code_id = fields.Many2one( - comodel_name='hs.code', - string='Intrastat Code', ondelete='restrict') + comodel_name="hs.code", string="Intrastat Code", ondelete="restrict" + ) - @api.onchange('product_id') + @api.onchange("product_id") def intrastat_product_id_change(self): if self.product_id: hs_code = self.product_id.get_hs_code_recursively() diff --git a/intrastat_product/models/hs_code.py b/intrastat_product/models/hs_code.py index e8aaeb4..91a82ed 100644 --- a/intrastat_product/models/hs_code.py +++ b/intrastat_product/models/hs_code.py @@ -3,7 +3,7 @@ # @author Alexis de Lattre # @author Luc de Meyer -from odoo import api, fields, models, _ +from odoo import _, api, fields, models from odoo.exceptions import ValidationError @@ -11,20 +11,26 @@ class HSCode(models.Model): _inherit = "hs.code" intrastat_unit_id = fields.Many2one( - comodel_name='intrastat.unit', - string='Intrastat Supplementary Unit') + comodel_name="intrastat.unit", string="Intrastat Supplementary Unit" + ) - @api.constrains('local_code') + @api.constrains("local_code") def _hs_code(self): if self.company_id.country_id.intrastat: if not self.local_code.isdigit(): - raise ValidationError(_( - "Intrastat Codes should only contain digits. " - "This is not the case for code '%s'.") - % self.local_code) + raise ValidationError( + _( + "Intrastat Codes should only contain digits. " + "This is not the case for code '%s'." + ) + % self.local_code + ) if len(self.local_code) != 8: - raise ValidationError(_( - "Intrastat Codes should " - "contain 8 digits. This is not the case for " - "Intrastat Code '%s' which has %d digits.") - % (self.local_code, len(self.local_code))) + raise ValidationError( + _( + "Intrastat Codes should " + "contain 8 digits. This is not the case for " + "Intrastat Code '%s' which has %d digits." + ) + % (self.local_code, len(self.local_code)) + ) diff --git a/intrastat_product/models/intrastat_product_declaration.py b/intrastat_product/models/intrastat_product_declaration.py index d5af916..1716798 100644 --- a/intrastat_product/models/intrastat_product_declaration.py +++ b/intrastat_product/models/intrastat_product_declaration.py @@ -3,116 +3,151 @@ # @author Alexis de Lattre # @author Luc de Meyer -from odoo import api, fields, models, _ -from odoo.exceptions import RedirectWarning, ValidationError, UserError -import odoo.addons.decimal_precision as dp -from datetime import datetime, date -from dateutil.relativedelta import relativedelta import logging +from datetime import date, datetime + +from dateutil.relativedelta import relativedelta + +from odoo import _, api, fields, models +from odoo.exceptions import RedirectWarning, UserError, ValidationError + _logger = logging.getLogger(__name__) class IntrastatProductDeclaration(models.Model): - _name = 'intrastat.product.declaration' + _name = "intrastat.product.declaration" _description = "Intrastat Product Report Base Object" - _rec_name = 'year_month' - _inherit = ['mail.thread', 'intrastat.common'] - _order = 'year_month desc, type, revision' + _rec_name = "year_month" + _inherit = ["mail.thread", "intrastat.common"] + _order = "year_month desc, type, revision" _sql_constraints = [ - ('date_uniq', - 'unique(year_month, company_id, type, revision)', - "A declaration of the same type already exists for this month !" - "\nYou should update the existing declaration " - "or change the revision number of this one."), + ( + "date_uniq", + "unique(year_month, company_id, type, revision)", + "A declaration of the same type already exists for this month !" + "\nYou should update the existing declaration " + "or change the revision number of this one.", + ) ] @api.model def default_get(self, fields_list): res = super(IntrastatProductDeclaration, self).default_get(fields_list) decl_date = fields.Date.context_today(self) - relativedelta(months=1) - res.update({ - 'year': str(decl_date.year), - 'month': decl_date.month, - }) + res.update({"year": str(decl_date.year), "month": decl_date.month}) return res company_id = fields.Many2one( - comodel_name='res.company', string='Company', readonly=True, - default=lambda self: self.env['res.company']._company_default_get()) + comodel_name="res.company", + string="Company", + readonly=True, + default=lambda self: self.env["res.company"]._company_default_get(), + ) company_country_code = fields.Char( - compute='_compute_company_country_code', - string='Company Country Code', readonly=True, store=True, - help="Used in views and methods of localization modules.") + compute="_compute_company_country_code", + string="Company Country Code", + readonly=True, + store=True, + help="Used in views and methods of localization modules.", + ) year = fields.Char( - string='Year', required=True, - states={'done': [('readonly', True)]}) - month = fields.Selection([ - (1, '01'), - (2, '02'), - (3, '03'), - (4, '04'), - (5, '05'), - (6, '06'), - (7, '07'), - (8, '08'), - (9, '09'), - (10, '10'), - (11, '11'), - (12, '12') - ], string='Month', required=True, - states={'done': [('readonly', True)]}) + string="Year", required=True, states={"done": [("readonly", True)]} + ) + month = fields.Selection( + selection=[ + ("01", "01"), + ("02", "02"), + ("03", "03"), + ("04", "04"), + ("05", "05"), + ("06", "06"), + ("07", "07"), + ("08", "08"), + ("09", "09"), + ("10", "10"), + ("11", "11"), + ("12", "12"), + ], + string="Month", + required=True, + states={"done": [("readonly", True)]}, + ) year_month = fields.Char( - compute='_compute_year_month', string='Period', readonly=True, - track_visibility='onchange', store=True, - help="Year and month of the declaration.") + compute="_compute_year_month", + string="Period", + readonly=True, + track_visibility="onchange", + store=True, + help="Year and month of the declaration.", + ) type = fields.Selection( - selection='_get_type', string='Type', required=True, - states={'done': [('readonly', True)]}, - track_visibility='onchange', help="Select the declaration type.") + selection="_get_type", + string="Type", + required=True, + states={"done": [("readonly", True)]}, + track_visibility="onchange", + help="Select the declaration type.", + ) action = fields.Selection( - selection='_get_action', - string='Action', required=True, - default='replace', - states={'done': [('readonly', True)]}, - track_visibility='onchange') + selection="_get_action", + string="Action", + required=True, + default="replace", + states={"done": [("readonly", True)]}, + track_visibility="onchange", + ) revision = fields.Integer( - string='Revision', default=1, - states={'done': [('readonly', True)]}, - help="Used to keep track of changes") + string="Revision", + default=1, + states={"done": [("readonly", True)]}, + help="Used to keep track of changes", + ) computation_line_ids = fields.One2many( - comodel_name='intrastat.product.computation.line', - inverse_name='parent_id', - string='Intrastat Product Computation Lines', - states={'done': [('readonly', True)]}) + comodel_name="intrastat.product.computation.line", + inverse_name="parent_id", + string="Intrastat Product Computation Lines", + states={"done": [("readonly", True)]}, + ) declaration_line_ids = fields.One2many( - comodel_name='intrastat.product.declaration.line', - inverse_name='parent_id', string='Intrastat Product Declaration Lines', - states={'done': [('readonly', True)]}) + comodel_name="intrastat.product.declaration.line", + inverse_name="parent_id", + string="Intrastat Product Declaration Lines", + states={"done": [("readonly", True)]}, + ) num_decl_lines = fields.Integer( - compute='_compute_numbers', string='Number of Declaration Lines', - store=True, track_visibility='onchange') + compute="_compute_numbers", + string="Number of Declaration Lines", + store=True, + track_visibility="onchange", + ) total_amount = fields.Integer( - compute='_compute_numbers', string='Total Fiscal Amount', store=True, - help="Total fiscal amount in company currency of the declaration.") + compute="_compute_numbers", + string="Total Fiscal Amount", + store=True, + help="Total fiscal amount in company currency of the declaration.", + ) currency_id = fields.Many2one( - 'res.currency', related='company_id.currency_id', string='Currency') + "res.currency", related="company_id.currency_id", string="Currency" + ) state = fields.Selection( - selection=[('draft', 'Draft'), - ('done', 'Done')], - string='State', readonly=True, track_visibility='onchange', - copy=False, default='draft', + selection=[("draft", "Draft"), ("done", "Done")], + string="State", + readonly=True, + track_visibility="onchange", + copy=False, + default="draft", help="State of the declaration. When the state is set to 'Done', " - "the parameters become read-only.") + "the parameters become read-only.", + ) note = fields.Text( - string='Notes', - help="You can add some comments here if you want.") + string="Notes", help="You can add some comments here if you want." + ) reporting_level = fields.Selection( - selection='_get_reporting_level', - string='Reporting Level', - states={'done': [('readonly', True)]}) - valid = fields.Boolean( - compute='_compute_check_validity', - string='Valid') + selection="_get_reporting_level", + string="Reporting Level", + states={"done": [("readonly", True)]}, + ) + valid = fields.Boolean(compute="_compute_check_validity", string="Valid") @api.model def _get_type(self): @@ -120,81 +155,83 @@ class IntrastatProductDeclaration(models.Model): company = self.env.user.company_id arrivals = company.intrastat_arrivals dispatches = company.intrastat_dispatches - if arrivals != 'exempt': - res.append(('arrivals', _('Declaration for Arrivals'))) - if dispatches != 'exempt': - res.append(('dispatches', _('Declaration for Dispatches'))) + if arrivals != "exempt": + res.append(("arrivals", _("Declaration for Arrivals"))) + if dispatches != "exempt": + res.append(("dispatches", _("Declaration for Dispatches"))) return res @api.model def _get_reporting_level(self): - return [ - ('standard', _('Standard')), - ('extended', _('Extended'))] + return [("standard", _("Standard")), ("extended", _("Extended"))] @api.model def _get_action(self): return [ - ('replace', _('Replace')), - ('append', _('Append')), - ('nihil', _('Nihil'))] + ("replace", _("Replace")), + ("append", _("Append")), + ("nihil", _("Nihil")), + ] - @api.depends('company_id') + @api.depends("company_id") def _compute_company_country_code(self): for this in self: if this.company_id: if not this.company_id.country_id: - raise ValidationError( - _("You must set company's country !")) - this.company_country_code = \ - this.company_id.country_id.code.lower() + raise ValidationError(_("You must set company's country !")) + this.company_country_code = this.company_id.country_id.code.lower() - @api.depends('year', 'month') + @api.depends("year", "month") def _compute_year_month(self): for this in self: if this.year and this.month: - this.year_month = '-'.join( - [this.year, format(this.month, '02')]) + this.year_month = "-".join([this.year, this.month]) - @api.depends('month') + @api.depends("month") def _compute_check_validity(self): """ TO DO: logic based upon computation lines """ for this in self: this.valid = True @api.model - @api.constrains('year') + @api.constrains("year") def _check_year(self): for this in self: - if len(this.year) != 4 or this.year[0] != '2': + if len(this.year) != 4 or this.year[0] != "2": raise ValidationError(_("Invalid Year !")) - @api.onchange('type') + @api.onchange("type") def _onchange_type(self): - if self.type == 'arrivals': - self.reporting_level = \ - self.company_id.intrastat_arrivals == 'extended' \ - and 'extended' or 'standard' - if self.type == 'dispatches': - self.reporting_level = \ - self.company_id.intrastat_dispatches == 'extended' \ - and 'extended' or 'standard' + if self.type == "arrivals": + self.reporting_level = ( + self.company_id.intrastat_arrivals == "extended" + and "extended" + or "standard" + ) + if self.type == "dispatches": + self.reporting_level = ( + self.company_id.intrastat_dispatches == "extended" + and "extended" + or "standard" + ) def copy(self, default=None): self.ensure_one() default = default or {} - default['revision'] = self.revision + 1 + default["revision"] = self.revision + 1 return super(IntrastatProductDeclaration, self).copy(default) def _account_config_warning(self, msg): - action = self.env.ref('account.action_account_config') + action = self.env.ref("account.action_account_config") raise RedirectWarning( - msg, action.id, - _('Go to Accounting Configuration Settings screen')) + msg, action.id, _("Go to Accounting Configuration Settings screen") + ) def _get_partner_country(self, inv_line): - country = inv_line.invoice_id.src_dest_country_id \ + country = ( + inv_line.invoice_id.src_dest_country_id or inv_line.invoice_id.partner_id.country_id + ) if not country.intrastat: country = False elif country == self.company_id.country_id: @@ -207,13 +244,13 @@ class IntrastatProductDeclaration(models.Model): return invoice.intrastat_transaction_id else: company = invoice.company_id - if invoice.type == 'out_invoice': + if invoice.type == "out_invoice": return company.intrastat_transaction_out_invoice - elif invoice.type == 'out_refund': + elif invoice.type == "out_refund": return company.intrastat_transaction_out_refund - elif invoice.type == 'in_invoice': + elif invoice.type == "in_invoice": return company.intrastat_transaction_in_invoice - elif invoice.type == 'in_refund': + elif invoice.type == "in_refund": return company.intrastat_transaction_in_refund def _get_weight_and_supplunits(self, inv_line, hs_code): @@ -222,10 +259,10 @@ class IntrastatProductDeclaration(models.Model): invoice = inv_line.invoice_id intrastat_unit_id = hs_code.intrastat_unit_id source_uom = inv_line.uom_id - weight_uom_categ = self._get_uom_refs('weight_uom_categ') - kg_uom = self._get_uom_refs('kg_uom') - pce_uom_categ = self._get_uom_refs('pce_uom_categ') - pce_uom = self._get_uom_refs('pce_uom') + weight_uom_categ = self._get_uom_refs("weight_uom_categ") + kg_uom = self._get_uom_refs("kg_uom") + pce_uom_categ = self._get_uom_refs("pce_uom_categ") + pce_uom = self._get_uom_refs("pce_uom") weight = suppl_unit_qty = 0.0 if not source_uom: @@ -233,28 +270,34 @@ class IntrastatProductDeclaration(models.Model): "Missing unit of measure on the line with %d " "product(s) '%s' on invoice '%s'." ) % (line_qty, product.name_get()[0][1], invoice.number) - note += "\n" + _( - "Please adjust this line manually.") + note += "\n" + _("Please adjust this line manually.") self._note += note return weight, suppl_unit_qty if intrastat_unit_id: target_uom = intrastat_unit_id.uom_id if not target_uom: - note = "\n" + _( - "Conversion from Intrastat Supplementary Unit '%s' to " - "Unit of Measure is not implemented yet." - ) % intrastat_unit_id.name - note += "\n" + _( - "Please correct the Intrastat Supplementary Unit " - "settings and regenerate the lines or adjust the lines " - "with Intrastat Code '%s' manually" - ) % hs_code.display_name + note = ( + "\n" + + _( + "Conversion from Intrastat Supplementary Unit '%s' to " + "Unit of Measure is not implemented yet." + ) + % intrastat_unit_id.name + ) + note += ( + "\n" + + _( + "Please correct the Intrastat Supplementary Unit " + "settings and regenerate the lines or adjust the lines " + "with Intrastat Code '%s' manually" + ) + % hs_code.display_name + ) self._note += note return weight, suppl_unit_qty if target_uom.category_id == source_uom.category_id: - suppl_unit_qty = source_uom._compute_quantity( - line_qty, target_uom) + suppl_unit_qty = source_uom._compute_quantity(line_qty, target_uom) else: note = "\n" + _( "Conversion from unit of measure '%s' to '%s' " @@ -263,7 +306,8 @@ class IntrastatProductDeclaration(models.Model): note += "\n" + _( "Please correct the unit of measure settings and " "regenerate the lines or adjust the impacted " - "lines manually") + "lines manually" + ) self._note += note return weight, suppl_unit_qty @@ -273,12 +317,13 @@ class IntrastatProductDeclaration(models.Model): weight = source_uom._compute_quantity(line_qty, kg_uom) elif source_uom.category_id == pce_uom_categ: if not product.weight: # re-create weight_net ? - note = "\n" + _( - "Missing weight on product %s." - ) % product.name_get()[0][1] + note = ( + "\n" + _("Missing weight on product %s.") % product.name_get()[0][1] + ) note += "\n" + _( "Please correct the product record and regenerate " - "the lines or adjust the impacted lines manually") + "the lines or adjust the impacted lines manually" + ) self._note += note return weight, suppl_unit_qty if source_uom == pce_uom: @@ -287,8 +332,9 @@ class IntrastatProductDeclaration(models.Model): # Here, I suppose that, on the product, the # weight is per PCE and not per uom_id # product.weight_net - weight = product.weight * \ - source_uom._compute_quantity(line_qty, pce_uom) + weight = product.weight * source_uom._compute_quantity( + line_qty, pce_uom + ) else: note = "\n" + _( "Conversion from unit of measure '%s' to 'Kg' " @@ -297,7 +343,8 @@ class IntrastatProductDeclaration(models.Model): note += "\n" + _( "Please correct the unit of measure settings and " "regenerate the lines or adjust the impacted lines " - "manually") + "manually" + ) self._note += note return weight, suppl_unit_qty @@ -306,8 +353,11 @@ class IntrastatProductDeclaration(models.Model): def _get_amount(self, inv_line): invoice = inv_line.invoice_id amount = invoice.currency_id._convert( - inv_line.price_subtotal, self.company_id.currency_id, - self.company_id, invoice.date_invoice) + inv_line.price_subtotal, + self.company_id.currency_id, + self.company_id, + invoice.date_invoice, + ) return amount def _get_region(self, inv_line): @@ -331,16 +381,19 @@ class IntrastatProductDeclaration(models.Model): """ region = False inv_type = inv_line.invoice_id.type - if inv_type in ('in_invoice', 'in_refund'): - po_lines = self.env['purchase.order.line'].search( - [('invoice_lines', 'in', inv_line.id)]) + if inv_type in ("in_invoice", "in_refund"): + po_lines = self.env["purchase.order.line"].search( + [("invoice_lines", "in", inv_line.id)] + ) if po_lines: if po_lines[0].move_ids: - region = po_lines[0].move_ids[0].location_dest_id\ - .get_intrastat_region() - elif inv_type in ('out_invoice', 'out_refund'): - so_lines = self.env['sale.order.line'].search( - [('invoice_lines', 'in', inv_line.id)]) + region = ( + po_lines[0].move_ids[0].location_dest_id.get_intrastat_region() + ) + elif inv_type in ("out_invoice", "out_refund"): + so_lines = self.env["sale.order.line"].search( + [("invoice_lines", "in", inv_line.id)] + ) if so_lines: so = so_lines[0].order_id region = so.warehouse_id.region_id @@ -350,13 +403,16 @@ class IntrastatProductDeclaration(models.Model): return region def _get_transport(self, inv_line): - transport = inv_line.invoice_id.intrastat_transport_id \ + transport = ( + inv_line.invoice_id.intrastat_transport_id or self.company_id.intrastat_transport_id + ) if not transport: msg = _( "The default Intrastat Transport Mode " "of the Company is not set, " - "please configure it first.") + "please configure it first." + ) self._account_config_warning(msg) return transport @@ -364,13 +420,15 @@ class IntrastatProductDeclaration(models.Model): # WARNING for v12: there are 2 incoterm fields on account.invoice # cf https://github.com/odoo/odoo/issues/31641 # the field to use is 'incoterm_id' defined in the 'account' module - incoterm = inv_line.invoice_id.incoterm_id \ - or self.company_id.intrastat_incoterm_id + incoterm = ( + inv_line.invoice_id.incoterm_id or self.company_id.intrastat_incoterm_id + ) if not incoterm: msg = _( "The default Incoterm " "of the Company is not set, " - "please configure it first.") + "please configure it first." + ) self._account_config_warning(msg) return incoterm @@ -382,9 +440,13 @@ class IntrastatProductDeclaration(models.Model): pass def _handle_invoice_accessory_cost( - self, invoice, lines_current_invoice, - total_inv_accessory_costs_cc, total_inv_product_cc, - total_inv_weight): + self, + invoice, + lines_current_invoice, + total_inv_accessory_costs_cc, + total_inv_product_cc, + total_inv_weight, + ): """ Affect accessory costs pro-rata of the value (or pro-rata of the weight if the goods of the invoice @@ -398,22 +460,24 @@ class IntrastatProductDeclaration(models.Model): if total_inv_product_cc: # pro-rata of the value for ac_line_vals in lines_current_invoice: - ac_line_vals['amount_accessory_cost_company_currency'] = ( - total_inv_accessory_costs_cc * - ac_line_vals['amount_company_currency'] / - total_inv_product_cc) + ac_line_vals["amount_accessory_cost_company_currency"] = ( + total_inv_accessory_costs_cc + * ac_line_vals["amount_company_currency"] + / total_inv_product_cc + ) elif total_inv_weight: # pro-rata of the weight for ac_line_vals in lines_current_invoice: - ac_line_vals['amount_accessory_cost_company_currency'] = ( - total_inv_accessory_costs_cc * - ac_line_vals['weight'] / - total_inv_weight) + ac_line_vals["amount_accessory_cost_company_currency"] = ( + total_inv_accessory_costs_cc + * ac_line_vals["weight"] + / total_inv_weight + ) else: for ac_line_vals in lines_current_invoice: - ac_line_vals['amount_accessory_cost_company_currency'] = ( - total_inv_accessory_costs_cc / - len(lines_current_invoice)) + ac_line_vals[ + "amount_accessory_cost_company_currency" + ] = total_inv_accessory_costs_cc / len(lines_current_invoice) def _prepare_invoice_domain(self): """ @@ -421,20 +485,22 @@ class IntrastatProductDeclaration(models.Model): with the country-specific logic for arrivals and dispatches. Cf. l10n_be_intrastat_product_declaration for an example """ - start_date = date(int(self.year), self.month, 1) + start_date = date(int(self.year), int(self.month), 1) end_date = start_date + relativedelta(day=1, months=+1, days=-1) domain = [ - ('date_invoice', '>=', start_date), - ('date_invoice', '<=', end_date), - ('state', 'in', ['open', 'in_payment', 'paid']), - ('intrastat_country', '=', True), - ('company_id', '=', self.company_id.id)] + ("date_invoice", ">=", start_date), + ("date_invoice", "<=", end_date), + ("state", "in", ["open", "in_payment", "paid"]), + ("intrastat_country", "=", True), + ("company_id", "=", self.company_id.id), + ] return domain def _is_product(self, invoice_line): - if ( - invoice_line.product_id and - invoice_line.product_id.type in ('product', 'consu')): + if invoice_line.product_id and invoice_line.product_id.type in ( + "product", + "consu", + ): return True else: return False @@ -450,7 +516,7 @@ class IntrastatProductDeclaration(models.Model): self._gather_invoices_init() domain = self._prepare_invoice_domain() - invoices = self.env['account.invoice'].search(domain) + invoices = self.env["account.move"].search(domain) for invoice in invoices: @@ -461,41 +527,49 @@ class IntrastatProductDeclaration(models.Model): for inv_line in invoice.invoice_line_ids: if ( - accessory_costs and - inv_line.product_id and - inv_line.product_id.is_accessory_cost): + accessory_costs + and inv_line.product_id + and inv_line.product_id.is_accessory_cost + ): acost = invoice.currency_id._convert( inv_line.price_subtotal, self.company_id.currency_id, self.company_id, - invoice.date_invoice) + invoice.date_invoice, + ) total_inv_accessory_costs_cc += acost continue if not inv_line.quantity: _logger.info( - 'Skipping invoice line %s qty %s ' - 'of invoice %s. Reason: qty = 0' - % (inv_line.name, inv_line.quantity, invoice.number)) + "Skipping invoice line %s qty %s " + "of invoice %s. Reason: qty = 0" + % (inv_line.name, inv_line.quantity, invoice.number) + ) continue partner_country = self._get_partner_country(inv_line) if not partner_country: _logger.info( - 'Skipping invoice line %s qty %s ' - 'of invoice %s. Reason: no partner_country' - % (inv_line.name, inv_line.quantity, invoice.number)) + "Skipping invoice line %s qty %s " + "of invoice %s. Reason: no partner_country" + % (inv_line.name, inv_line.quantity, invoice.number) + ) continue - if any([ + if any( + [ tax.exclude_from_intrastat_if_present - for tax in inv_line.invoice_line_tax_ids]): + for tax in inv_line.invoice_line_tax_ids + ] + ): _logger.info( - 'Skipping invoice line %s ' - 'qty %s of invoice %s. Reason: ' - 'tax.exclude_from_intrastat_if_present' - % (inv_line.name, inv_line.quantity, invoice.number)) + "Skipping invoice line %s " + "qty %s of invoice %s. Reason: " + "tax.exclude_from_intrastat_if_present" + % (inv_line.name, inv_line.quantity, invoice.number) + ) continue if inv_line.hs_code_id: @@ -505,79 +579,82 @@ class IntrastatProductDeclaration(models.Model): if not hs_code: note = "\n" + _( "Missing H.S. code on product %s. " - "This product is present in invoice %s.") % ( - inv_line.product_id.name_get()[0][1], - inv_line.invoice_id.number) + "This product is present in invoice %s." + ) % ( + inv_line.product_id.name_get()[0][1], + inv_line.invoice_id.number, + ) self._note += note continue else: _logger.info( - 'Skipping invoice line %s qty %s ' - 'of invoice %s. Reason: no product nor hs_code' - % (inv_line.name, inv_line.quantity, invoice.number)) + "Skipping invoice line %s qty %s " + "of invoice %s. Reason: no product nor hs_code" + % (inv_line.name, inv_line.quantity, invoice.number) + ) continue - intrastat_transaction = \ - self._get_intrastat_transaction(inv_line) + intrastat_transaction = self._get_intrastat_transaction(inv_line) weight, suppl_unit_qty = self._get_weight_and_supplunits( - inv_line, hs_code) + inv_line, hs_code + ) total_inv_weight += weight amount_company_currency = self._get_amount(inv_line) total_inv_product_cc += amount_company_currency - product_origin_country = self._get_product_origin_country( - inv_line) + product_origin_country = self._get_product_origin_country(inv_line) region = self._get_region(inv_line) line_vals = { - 'parent_id': self.id, - 'invoice_line_id': inv_line.id, - 'src_dest_country_id': partner_country.id, - 'product_id': inv_line.product_id.id, - 'hs_code_id': hs_code.id, - 'weight': weight, - 'suppl_unit_qty': suppl_unit_qty, - 'amount_company_currency': amount_company_currency, - 'amount_accessory_cost_company_currency': 0.0, - 'transaction_id': intrastat_transaction.id, - 'product_origin_country_id': - product_origin_country.id or False, - 'region_id': region and region.id or False, + "parent_id": self.id, + "invoice_line_id": inv_line.id, + "src_dest_country_id": partner_country.id, + "product_id": inv_line.product_id.id, + "hs_code_id": hs_code.id, + "weight": weight, + "suppl_unit_qty": suppl_unit_qty, + "amount_company_currency": amount_company_currency, + "amount_accessory_cost_company_currency": 0.0, + "transaction_id": intrastat_transaction.id, + "product_origin_country_id": product_origin_country.id or False, + "region_id": region and region.id or False, } # extended declaration if self._extended: transport = self._get_transport(inv_line) - line_vals.update({ - 'transport_id': transport.id, - }) + line_vals.update({"transport_id": transport.id}) self._update_computation_line_vals(inv_line, line_vals) if line_vals: - lines_current_invoice.append((line_vals)) + lines_current_invoice.append(line_vals) self._handle_invoice_accessory_cost( - invoice, lines_current_invoice, - total_inv_accessory_costs_cc, total_inv_product_cc, - total_inv_weight) + invoice, + lines_current_invoice, + total_inv_accessory_costs_cc, + total_inv_product_cc, + total_inv_weight, + ) for line_vals in lines_current_invoice: if ( - not line_vals['amount_company_currency'] and - not - line_vals['amount_accessory_cost_company_currency']): - inv_line = self.env['account.invoice.line'].browse( - line_vals['invoice_line_id']) + not line_vals["amount_company_currency"] + and not line_vals["amount_accessory_cost_company_currency"] + ): + inv_line = self.env["account.move.line"].browse( + line_vals["invoice_line_id"] + ) _logger.info( - 'Skipping invoice line %s qty %s ' - 'of invoice %s. Reason: price_subtotal = 0 ' - 'and accessory costs = 0' - % (inv_line.name, inv_line.quantity, - inv_line.invoice_id.number)) + "Skipping invoice line %s qty %s " + "of invoice %s. Reason: price_subtotal = 0 " + "and accessory costs = 0" + % (inv_line.name, inv_line.quantity, inv_line.invoice_id.number) + ) continue lines.append(line_vals) @@ -585,10 +662,10 @@ class IntrastatProductDeclaration(models.Model): def _get_uom_refs(self, ref): uom_refs = { - 'weight_uom_categ': self.env.ref('uom.product_uom_categ_kgm'), - 'kg_uom': self.env.ref('uom.product_uom_kgm'), - 'pce_uom_categ': self.env.ref('uom.product_uom_categ_unit'), - 'pce_uom': self.env.ref('uom.product_uom_unit') + "weight_uom_categ": self.env.ref("uom.product_uom_categ_kgm"), + "kg_uom": self.env.ref("uom.product_uom_kgm"), + "pce_uom_categ": self.env.ref("uom.product_uom_categ_unit"), + "pce_uom": self.env.ref("uom.product_uom_unit"), } return uom_refs[ref] @@ -596,12 +673,13 @@ class IntrastatProductDeclaration(models.Model): self.ensure_one() self.message_post(body=_("Generate Lines from Invoices")) self._check_generate_lines() - self._note = '' + self._note = "" if ( - self.type == 'arrivals' and - self.company_id.intrastat_arrivals == 'extended') or ( - self.type == 'dispatches' and - self.company_id.intrastat_dispatches == 'extended'): + self.type == "arrivals" and self.company_id.intrastat_arrivals == "extended" + ) or ( + self.type == "dispatches" + and self.company_id.intrastat_dispatches == "extended" + ): self._extended = True else: self._extended = False @@ -611,29 +689,36 @@ class IntrastatProductDeclaration(models.Model): lines = self._gather_invoices() if not lines: - self.action = 'nihil' - note = "\n" + \ - _("No records found for the selected period !") + '\n' + \ - _("The Declaration Action has been set to 'nihil'.") + self.action = "nihil" + note = ( + "\n" + + _("No records found for the selected period !") + + "\n" + + _("The Declaration Action has been set to 'nihil'.") + ) self._note += note else: - self.write({'computation_line_ids': [(0, 0, x) for x in lines]}) + self.write({"computation_line_ids": [(0, 0, x) for x in lines]}) if self._note: - note_header = '\n\n>>> ' + fields.Datetime.to_string( - fields.Datetime.context_timestamp(self, datetime.now())) + '\n' - self.note = note_header + self._note + (self.note or '') - result_view = self.env.ref( - 'intrastat_base.intrastat_result_view_form') + note_header = ( + "\n\n>>> " + + fields.Datetime.to_string( + fields.Datetime.context_timestamp(self, datetime.now()) + ) + + "\n" + ) + self.note = note_header + self._note + (self.note or "") + result_view = self.env.ref("intrastat_base.intrastat_result_view_form") return { - 'name': _("Generate lines from invoices: results"), - 'view_type': 'form', - 'view_mode': 'form', - 'res_model': 'intrastat.result.view', - 'view_id': result_view.id, - 'target': 'new', - 'context': dict(self._context, note=self._note), - 'type': 'ir.actions.act_window', + "name": _("Generate lines from invoices: results"), + "view_type": "form", + "view_mode": "form", + "res_model": "intrastat.result.view", + "view_id": result_view.id, + "target": "new", + "context": dict(self._context, note=self._note), + "type": "ir.actions.act_window", } return True @@ -641,70 +726,65 @@ class IntrastatProductDeclaration(models.Model): @api.model def _group_line_hashcode_fields(self, computation_line): return { - 'country': computation_line.src_dest_country_id.id or False, - 'hs_code_id': computation_line.hs_code_id.id or False, - 'intrastat_unit': computation_line.intrastat_unit_id.id or False, - 'transaction': computation_line.transaction_id.id or False, - 'transport': computation_line.transport_id.id or False, - 'region': computation_line.region_id.id or False, - 'product_origin_country': - computation_line.product_origin_country_id.id or False, + "country": computation_line.src_dest_country_id.id or False, + "hs_code_id": computation_line.hs_code_id.id or False, + "intrastat_unit": computation_line.intrastat_unit_id.id or False, + "transaction": computation_line.transaction_id.id or False, + "transport": computation_line.transport_id.id or False, + "region": computation_line.region_id.id or False, + "product_origin_country": computation_line.product_origin_country_id.id + or False, } def group_line_hashcode(self, computation_line): hc_fields = self._group_line_hashcode_fields(computation_line) - hashcode = '-'.join([str(f) for f in hc_fields.values()]) + hashcode = "-".join([str(f) for f in hc_fields.values()]) return hashcode @api.model def _prepare_grouped_fields(self, computation_line, fields_to_sum): vals = { - 'src_dest_country_id': computation_line.src_dest_country_id.id, - 'intrastat_unit_id': computation_line.intrastat_unit_id.id, - 'hs_code_id': computation_line.hs_code_id.id, - 'transaction_id': computation_line.transaction_id.id, - 'transport_id': computation_line.transport_id.id, - 'region_id': computation_line.region_id.id, - 'parent_id': computation_line.parent_id.id, - 'product_origin_country_id': - computation_line.product_origin_country_id.id, - 'amount_company_currency': 0.0, - } + "src_dest_country_id": computation_line.src_dest_country_id.id, + "intrastat_unit_id": computation_line.intrastat_unit_id.id, + "hs_code_id": computation_line.hs_code_id.id, + "transaction_id": computation_line.transaction_id.id, + "transport_id": computation_line.transport_id.id, + "region_id": computation_line.region_id.id, + "parent_id": computation_line.parent_id.id, + "product_origin_country_id": computation_line.product_origin_country_id.id, + "amount_company_currency": 0.0, + } for field in fields_to_sum: vals[field] = 0.0 return vals def _fields_to_sum(self): - fields_to_sum = [ - 'weight', - 'suppl_unit_qty', - ] + fields_to_sum = ["weight", "suppl_unit_qty"] return fields_to_sum @api.model def _prepare_declaration_line(self, computation_lines): fields_to_sum = self._fields_to_sum() - vals = self._prepare_grouped_fields( - computation_lines[0], fields_to_sum) + vals = self._prepare_grouped_fields(computation_lines[0], fields_to_sum) for computation_line in computation_lines: for field in fields_to_sum: vals[field] += computation_line[field] - vals['amount_company_currency'] += ( - computation_line['amount_company_currency'] + - computation_line['amount_accessory_cost_company_currency']) + vals["amount_company_currency"] += ( + computation_line["amount_company_currency"] + + computation_line["amount_accessory_cost_company_currency"] + ) # round, otherwise odoo with truncate (6.7 -> 6... instead of 7 !) for field in fields_to_sum: vals[field] = int(round(vals[field])) - if not vals['weight']: - vals['weight'] = 1 - vals['amount_company_currency'] = int(round( - vals['amount_company_currency'])) + if not vals["weight"]: + vals["weight"] = 1 + vals["amount_company_currency"] = int(round(vals["amount_company_currency"])) return vals def generate_declaration(self): """ generate declaration lines """ self.ensure_one() - assert self.valid, 'Computation lines are not valid' + assert self.valid, "Computation lines are not valid" self.message_post(body=_("Generate Declaration Lines")) # Delete existing declaration lines self.declaration_line_ids.unlink() @@ -721,7 +801,7 @@ class IntrastatProductDeclaration(models.Model): vals = self._prepare_declaration_line(cl_lines) declaration_line = ipdl.create(vals) for cl in cl_lines: - cl.write({'declaration_line_id': declaration_line.id}) + cl.write({"declaration_line_id": declaration_line.id}) return True def generate_xml(self): @@ -733,23 +813,23 @@ class IntrastatProductDeclaration(models.Model): xml_string = self._generate_xml() if xml_string: attach_id = self._attach_xml_file( - xml_string, '%s_%s' % (self.type, self.revision)) + xml_string, "{}_{}".format(self.type, self.revision) + ) return self._open_attach_view(attach_id) else: - raise UserError( - _("No XML File has been generated.")) + raise UserError(_("No XML File has been generated.")) def create_xls(self): - if self.env.context.get('computation_lines'): - report_file = 'instrastat_transactions' + if self.env.context.get("computation_lines"): + report_file = "instrastat_transactions" else: - report_file = 'instrastat_declaration_lines' + report_file = "instrastat_declaration_lines" return { - 'type': 'ir.actions.report', - 'report_type': 'xlsx', - 'report_name': 'intrastat_product.product_declaration_xls', - 'context': dict(self.env.context, report_file=report_file), - 'data': {'dynamic_report': True}, + "type": "ir.actions.report", + "report_type": "xlsx", + "report_name": "intrastat_product.product_declaration_xls", + "context": dict(self.env.context, report_file=report_file), + "data": {"dynamic_report": True}, } @api.model @@ -758,11 +838,18 @@ class IntrastatProductDeclaration(models.Model): Update list in custom module to add/drop columns or change order """ return [ - 'product', 'product_origin_country', - 'hs_code', 'src_dest_country', - 'amount_company_currency', 'accessory_cost', - 'transaction', 'weight', 'suppl_unit_qty', 'suppl_unit', - 'transport', 'invoice', + "product", + "product_origin_country", + "hs_code", + "src_dest_country", + "amount_company_currency", + "accessory_cost", + "transaction", + "weight", + "suppl_unit_qty", + "suppl_unit", + "transport", + "invoice", ] @api.model @@ -771,9 +858,14 @@ class IntrastatProductDeclaration(models.Model): Update list in custom module to add/drop columns or change order """ return [ - 'hs_code', 'src_dest_country', 'amount_company_currency', - 'transaction', 'weight', 'suppl_unit_qty', 'suppl_unit', - 'transport', + "hs_code", + "src_dest_country", + "amount_company_currency", + "transaction", + "weight", + "suppl_unit_qty", + "suppl_unit", + "transport", ] @api.model @@ -785,82 +877,91 @@ class IntrastatProductDeclaration(models.Model): return {} def done(self): - self.write({'state': 'done'}) + self.write({"state": "done"}) def back2draft(self): - self.write({'state': 'draft'}) + self.write({"state": "draft"}) class IntrastatProductComputationLine(models.Model): - _name = 'intrastat.product.computation.line' + _name = "intrastat.product.computation.line" _description = "Intrastat Product Computataion Lines" parent_id = fields.Many2one( - 'intrastat.product.declaration', - string='Intrastat Product Declaration', - ondelete='cascade', readonly=True) - company_id = fields.Many2one(related='parent_id.company_id') + "intrastat.product.declaration", + string="Intrastat Product Declaration", + ondelete="cascade", + readonly=True, + ) + company_id = fields.Many2one(related="parent_id.company_id") company_currency_id = fields.Many2one( - related='company_id.currency_id', string="Company currency") - type = fields.Selection(related='parent_id.type') - reporting_level = fields.Selection(related='parent_id.reporting_level') - valid = fields.Boolean( - compute='_compute_check_validity', - string='Valid') + related="company_id.currency_id", string="Company currency" + ) + type = fields.Selection(related="parent_id.type") + reporting_level = fields.Selection(related="parent_id.reporting_level") + valid = fields.Boolean(compute="_compute_check_validity", string="Valid") invoice_line_id = fields.Many2one( - 'account.invoice.line', string='Invoice Line', readonly=True) + "account.move.line", string="Invoice Line", readonly=True + ) invoice_id = fields.Many2one( - 'account.invoice', related='invoice_line_id.invoice_id', - string='Invoice') + "account.move", related="invoice_line_id.move_id", string="Invoice" + ) declaration_line_id = fields.Many2one( - 'intrastat.product.declaration.line', - string='Declaration Line', readonly=True) + "intrastat.product.declaration.line", string="Declaration Line", readonly=True + ) src_dest_country_id = fields.Many2one( - 'res.country', string='Country', + "res.country", + string="Country", help="Country of Origin/Destination", - domain=[('intrastat', '=', True)]) + domain=[("intrastat", "=", True)], + ) product_id = fields.Many2one( - 'product.product', related='invoice_line_id.product_id') - hs_code_id = fields.Many2one( - 'hs.code', string='Intrastat Code') + "product.product", related="invoice_line_id.product_id" + ) + hs_code_id = fields.Many2one("hs.code", string="Intrastat Code") intrastat_unit_id = fields.Many2one( - 'intrastat.unit', related='hs_code_id.intrastat_unit_id', - string='Suppl. Unit', help="Intrastat Supplementary Unit") + "intrastat.unit", + related="hs_code_id.intrastat_unit_id", + string="Suppl. Unit", + help="Intrastat Supplementary Unit", + ) weight = fields.Float( - string='Weight', - digits=dp.get_precision('Stock Weight'), help="Net weight in Kg") + string="Weight", digits="Stock Weight", help="Net weight in Kg" + ) suppl_unit_qty = fields.Float( - string='Suppl. Unit Qty', - digits=dp.get_precision('Product Unit of Measure'), - help="Supplementary Units Quantity") + string="Suppl. Unit Qty", + digits="Product Unit of Measure", + help="Supplementary Units Quantity", + ) amount_company_currency = fields.Float( - string='Fiscal Value', - digits=dp.get_precision('Account'), required=True, + string="Fiscal Value", + digits="Account", + required=True, help="Amount in company currency to write in the declaration. " "Amount in company currency = amount in invoice currency " - "converted to company currency with the rate of the invoice date.") + "converted to company currency with the rate of the invoice date.", + ) amount_accessory_cost_company_currency = fields.Float( - string='Accessory Costs', - digits=dp.get_precision('Account'), + string="Accessory Costs", + digits="Account", help="Amount in company currency of the accessory costs related to " "this invoice line (by default, these accessory costs are computed " - "at the pro-rata of the amount of each invoice line.") + "at the pro-rata of the amount of each invoice line.", + ) transaction_id = fields.Many2one( - 'intrastat.transaction', - string='Intrastat Transaction') - region_id = fields.Many2one( - 'intrastat.region', string='Intrastat Region') + "intrastat.transaction", string="Intrastat Transaction" + ) + region_id = fields.Many2one("intrastat.region", string="Intrastat Region") # extended declaration - incoterm_id = fields.Many2one( - 'account.incoterms', string='Incoterm') - transport_id = fields.Many2one( - 'intrastat.transport_mode', - string='Transport Mode') + incoterm_id = fields.Many2one("account.incoterms", string="Incoterm") + transport_id = fields.Many2one("intrastat.transport_mode", string="Transport Mode") product_origin_country_id = fields.Many2one( - 'res.country', string='Country of Origin of the Product', - help="Country of origin of the product i.e. product 'made in ____'") + "res.country", + string="Country of Origin of the Product", + help="Country of origin of the product i.e. product 'made in ____'", + ) - @api.depends('transport_id') + @api.depends("transport_id") def _compute_check_validity(self): """ TO DO: logic based upon fields """ for this in self: @@ -869,7 +970,7 @@ class IntrastatProductComputationLine(models.Model): # TODO: product_id is a readonly related field 'invoice_line_id.product_id' # so the onchange is non-sense. Either we convert product_id to a regular # field or we keep it a related field and we remove this onchange - @api.onchange('product_id') + @api.onchange("product_id") def _onchange_product(self): self.weight = 0.0 self.suppl_unit_qty = 0.0 @@ -877,59 +978,65 @@ class IntrastatProductComputationLine(models.Model): self.intrastat_unit_id = False if self.product_id: self.intrastat_code_id = self.product_id.intrastat_id - self.intrastat_unit_id =\ - self.product_id.intrastat_id.intrastat_unit_id + self.intrastat_unit_id = self.product_id.intrastat_id.intrastat_unit_id if not self.intrastat_unit_id: self.weight = self.product_id.weight class IntrastatProductDeclarationLine(models.Model): - _name = 'intrastat.product.declaration.line' + _name = "intrastat.product.declaration.line" _description = "Intrastat Product Declaration Lines" parent_id = fields.Many2one( - 'intrastat.product.declaration', - string='Intrastat Product Declaration', - ondelete='cascade', readonly=True) - company_id = fields.Many2one(related='parent_id.company_id') + "intrastat.product.declaration", + string="Intrastat Product Declaration", + ondelete="cascade", + readonly=True, + ) + company_id = fields.Many2one(related="parent_id.company_id") company_currency_id = fields.Many2one( - related='company_id.currency_id', string="Company currency") - type = fields.Selection(related='parent_id.type') - reporting_level = fields.Selection(related='parent_id.reporting_level') + related="company_id.currency_id", string="Company currency" + ) + type = fields.Selection(related="parent_id.type") + reporting_level = fields.Selection(related="parent_id.reporting_level") computation_line_ids = fields.One2many( - 'intrastat.product.computation.line', 'declaration_line_id', - string='Computation Lines', readonly=True) + "intrastat.product.computation.line", + "declaration_line_id", + string="Computation Lines", + readonly=True, + ) src_dest_country_id = fields.Many2one( - 'res.country', string='Country', + "res.country", + string="Country", help="Country of Origin/Destination", - domain=[('intrastat', '=', True)]) - hs_code_id = fields.Many2one( - 'hs.code', - string='Intrastat Code') + domain=[("intrastat", "=", True)], + ) + hs_code_id = fields.Many2one("hs.code", string="Intrastat Code") intrastat_unit_id = fields.Many2one( - 'intrastat.unit', related='hs_code_id.intrastat_unit_id', - string='Suppl. Unit', help="Intrastat Supplementary Unit") - weight = fields.Integer( - string='Weight', help="Net weight in Kg") + "intrastat.unit", + related="hs_code_id.intrastat_unit_id", + string="Suppl. Unit", + help="Intrastat Supplementary Unit", + ) + weight = fields.Integer(string="Weight", help="Net weight in Kg") suppl_unit_qty = fields.Integer( - string='Suppl. Unit Qty', - help="Supplementary Units Quantity") + string="Suppl. Unit Qty", help="Supplementary Units Quantity" + ) amount_company_currency = fields.Integer( - string='Fiscal Value', + string="Fiscal Value", help="Amount in company currency to write in the declaration. " "Amount in company currency = amount in invoice currency " - "converted to company currency with the rate of the invoice date.") + "converted to company currency with the rate of the invoice date.", + ) transaction_id = fields.Many2one( - 'intrastat.transaction', - string='Intrastat Transaction') - region_id = fields.Many2one( - 'intrastat.region', string='Intrastat Region') + "intrastat.transaction", string="Intrastat Transaction" + ) + region_id = fields.Many2one("intrastat.region", string="Intrastat Region") # extended declaration - incoterm_id = fields.Many2one( - 'account.incoterms', string='Incoterm') - transport_id = fields.Many2one( - 'intrastat.transport_mode', - string='Transport Mode') + incoterm_id = fields.Many2one("account.incoterms", string="Incoterm") + transport_id = fields.Many2one("intrastat.transport_mode", string="Transport Mode") product_origin_country_id = fields.Many2one( - 'res.country', string='Country of Origin of the Product', - help="Country of origin of the product i.e. product 'made in ____'") + "res.country", + string="Country of Origin of the Product", + help="Country of origin of the product i.e. product 'made in ____'", + ) diff --git a/intrastat_product/models/intrastat_region.py b/intrastat_product/models/intrastat_region.py index d320faa..74e28ed 100644 --- a/intrastat_product/models/intrastat_region.py +++ b/intrastat_product/models/intrastat_region.py @@ -5,19 +5,24 @@ from odoo import fields, models class IntrastatRegion(models.Model): - _name = 'intrastat.region' + _name = "intrastat.region" _description = "Intrastat Region" _sql_constraints = [ - ('intrastat_region_code_unique', - 'UNIQUE(code, country_id)', # TODO add company_id ? - 'Code must be unique.')] + ( + "intrastat_region_code_unique", + "UNIQUE(code, country_id)", # TODO add company_id ? + "Code must be unique.", + ) + ] - code = fields.Char(string='Code', required=True) + code = fields.Char(string="Code", required=True) country_id = fields.Many2one( - comodel_name='res.country', - string='Country', required=True) - name = fields.Char(string='Name', translate=True) - description = fields.Char(string='Description') + comodel_name="res.country", string="Country", required=True + ) + name = fields.Char(string="Name", translate=True) + description = fields.Char(string="Description") company_id = fields.Many2one( - comodel_name='res.company', string='Company', - default=lambda self: self.env['res.company']._company_default_get()) + comodel_name="res.company", + string="Company", + default=lambda self: self.env["res.company"]._company_default_get(), + ) diff --git a/intrastat_product/models/intrastat_transaction.py b/intrastat_product/models/intrastat_transaction.py index efa517f..9267805 100644 --- a/intrastat_product/models/intrastat_transaction.py +++ b/intrastat_product/models/intrastat_transaction.py @@ -7,27 +7,32 @@ from odoo import api, fields, models class IntrastatTransaction(models.Model): - _name = 'intrastat.transaction' + _name = "intrastat.transaction" _description = "Intrastat Transaction" - _order = 'code' - _sql_constraints = [( - 'intrastat_transaction_code_unique', - 'UNIQUE(code, company_id)', - 'Code must be unique.')] + _order = "code" + _sql_constraints = [ + ( + "intrastat_transaction_code_unique", + "UNIQUE(code, company_id)", + "Code must be unique.", + ) + ] - code = fields.Char(string='Code', required=True) - description = fields.Text(string='Description') + code = fields.Char(string="Code", required=True) + description = fields.Text(string="Description") company_id = fields.Many2one( - comodel_name='res.company', string='Company', - default=lambda self: self.env['res.company']._company_default_get()) + comodel_name="res.company", + string="Company", + default=lambda self: self.env["res.company"]._company_default_get(), + ) - @api.depends('code', 'description') + @api.depends("code", "description") def name_get(self): res = [] for this in self: name = this.code if this.description: - name += ' ' + this.description - name = len(name) > 55 and name[:55] + '...' or name + name += " " + this.description + name = len(name) > 55 and name[:55] + "..." or name res.append((this.id, name)) return res diff --git a/intrastat_product/models/intrastat_transport_mode.py b/intrastat_product/models/intrastat_transport_mode.py index ec28a23..1d816b9 100644 --- a/intrastat_product/models/intrastat_transport_mode.py +++ b/intrastat_product/models/intrastat_transport_mode.py @@ -7,22 +7,21 @@ from odoo import api, fields, models class IntrastatTransportMode(models.Model): - _name = 'intrastat.transport_mode' + _name = "intrastat.transport_mode" _description = "Intrastat Transport Mode" - _order = 'code' - _sql_constraints = [( - 'intrastat_transport_code_unique', - 'UNIQUE(code)', - 'Code must be unique.')] + _order = "code" + _sql_constraints = [ + ("intrastat_transport_code_unique", "UNIQUE(code)", "Code must be unique.") + ] - code = fields.Char(string='Code', required=True) - name = fields.Char(string='Name', required=True, translate=True) - description = fields.Char(string='Description', translate=True) + code = fields.Char(string="Code", required=True) + name = fields.Char(string="Name", required=True, translate=True) + description = fields.Char(string="Description", translate=True) - @api.depends('name', 'code') + @api.depends("name", "code") def name_get(self): res = [] for mode in self: - name = '%s. %s' % (mode.code, mode.name) + name = "{}. {}".format(mode.code, mode.name) res.append((mode.id, name)) return res diff --git a/intrastat_product/models/intrastat_unit.py b/intrastat_product/models/intrastat_unit.py index 7b08140..60b298c 100644 --- a/intrastat_product/models/intrastat_unit.py +++ b/intrastat_product/models/intrastat_unit.py @@ -7,13 +7,15 @@ from odoo import fields, models class IntrastatUnit(models.Model): - _name = 'intrastat.unit' - _description = 'Intrastat Supplementary Units' + _name = "intrastat.unit" + _description = "Intrastat Supplementary Units" - name = fields.Char(string='Name', required=True) - description = fields.Char(string='Description', required=True) + name = fields.Char(string="Name", required=True) + description = fields.Char(string="Description", required=True) uom_id = fields.Many2one( - comodel_name='uom.uom', string='Regular UoM', + comodel_name="uom.uom", + string="Regular UoM", help="Select the regular Unit of Measure of Odoo that corresponds " - "to this Intrastat Supplementary Unit.") + "to this Intrastat Supplementary Unit.", + ) active = fields.Boolean(default=True) diff --git a/intrastat_product/models/res_company.py b/intrastat_product/models/res_company.py index 4a8bad1..70e361b 100644 --- a/intrastat_product/models/res_company.py +++ b/intrastat_product/models/res_company.py @@ -7,66 +7,89 @@ from odoo import api, fields, models class ResCompany(models.Model): - _inherit = 'res.company' + _inherit = "res.company" intrastat_incoterm_id = fields.Many2one( - comodel_name='account.incoterms', - string='Default Incoterm for Intrastat', + comodel_name="account.incoterms", + string="Default Incoterm for Intrastat", help="International Commercial Terms are a series of " - "predefined commercial terms used in international " - "transactions.") + "predefined commercial terms used in international " + "transactions.", + ) intrastat_arrivals = fields.Selection( - selection='_intrastat_arrivals', string='Arrivals', - default='extended', required=True) + selection="_intrastat_arrivals", + string="Arrivals", + default="extended", + required=True, + ) intrastat_dispatches = fields.Selection( - selection='_intrastat_dispatches', string='Dispatches', - default='extended', required=True) + selection="_intrastat_dispatches", + string="Dispatches", + default="extended", + required=True, + ) intrastat_transport_id = fields.Many2one( - comodel_name='intrastat.transport_mode', - string='Default Transport Mode', ondelete='restrict') + comodel_name="intrastat.transport_mode", + string="Default Transport Mode", + ondelete="restrict", + ) intrastat = fields.Char( - string='Intrastat Declaration', store=True, readonly=True, - compute='_compute_intrastat') + string="Intrastat Declaration", + store=True, + readonly=True, + compute="_compute_intrastat", + ) intrastat_region_id = fields.Many2one( - comodel_name='intrastat.region', - string='Default Intrastat Region') + comodel_name="intrastat.region", string="Default Intrastat Region" + ) intrastat_transaction_out_invoice = fields.Many2one( - comodel_name='intrastat.transaction', - string='Default Intrastat Transaction For Customer Invoice') + comodel_name="intrastat.transaction", + string="Default Intrastat Transaction For Customer Invoice", + ) intrastat_transaction_out_refund = fields.Many2one( - comodel_name='intrastat.transaction', - string='Default Intrastat Transaction for Customer Refunds') + comodel_name="intrastat.transaction", + string="Default Intrastat Transaction for Customer Refunds", + ) intrastat_transaction_in_invoice = fields.Many2one( - comodel_name='intrastat.transaction', - string='Default Intrastat Transaction For Supplier Invoices') + comodel_name="intrastat.transaction", + string="Default Intrastat Transaction For Supplier Invoices", + ) intrastat_transaction_in_refund = fields.Many2one( - comodel_name='intrastat.transaction', - string='Default Intrastat Transaction For Supplier Refunds') + comodel_name="intrastat.transaction", + string="Default Intrastat Transaction For Supplier Refunds", + ) intrastat_accessory_costs = fields.Boolean( - string='Include Accessory Costs in Fiscal Value of Product') + string="Include Accessory Costs in Fiscal Value of Product" + ) @api.model def _intrastat_arrivals(self): return [ - ('exempt', 'Exempt'), - ('standard', 'Standard'), - ('extended', 'Extended')] + ("exempt", "Exempt"), + ("standard", "Standard"), + ("extended", "Extended"), + ] @api.model def _intrastat_dispatches(self): return [ - ('exempt', 'Exempt'), - ('standard', 'Standard'), - ('extended', 'Extended')] + ("exempt", "Exempt"), + ("standard", "Standard"), + ("extended", "Extended"), + ] - @api.depends('intrastat_arrivals', 'intrastat_dispatches') + @api.depends("intrastat_arrivals", "intrastat_dispatches") def _compute_intrastat(self): for this in self: - if this.intrastat_arrivals == 'exempt' \ - and this.intrastat_dispatches == 'exempt': - this.intrastat = 'exempt' - elif this.intrastat_arrivals == 'extended' \ - or this.intrastat_dispatches == 'extended': - this.intrastat = 'extended' + if ( + this.intrastat_arrivals == "exempt" + and this.intrastat_dispatches == "exempt" + ): + this.intrastat = "exempt" + elif ( + this.intrastat_arrivals == "extended" + or this.intrastat_dispatches == "extended" + ): + this.intrastat = "extended" else: - this.intrastat = 'standard' + this.intrastat = "standard" diff --git a/intrastat_product/models/res_config_settings.py b/intrastat_product/models/res_config_settings.py index abe3b86..19605e0 100644 --- a/intrastat_product/models/res_config_settings.py +++ b/intrastat_product/models/res_config_settings.py @@ -6,28 +6,38 @@ from odoo import fields, models class ResConfigSettings(models.TransientModel): - _inherit = 'res.config.settings' + _inherit = "res.config.settings" intrastat_incoterm_id = fields.Many2one( - related='company_id.intrastat_incoterm_id', readonly=False) + related="company_id.intrastat_incoterm_id", readonly=False + ) intrastat_arrivals = fields.Selection( - related='company_id.intrastat_arrivals', readonly=False) + related="company_id.intrastat_arrivals", readonly=False + ) intrastat_dispatches = fields.Selection( - related='company_id.intrastat_dispatches', readonly=False) - intrastat = fields.Char(related='company_id.intrastat') + related="company_id.intrastat_dispatches", readonly=False + ) + intrastat = fields.Char(related="company_id.intrastat") intrastat_transport_id = fields.Many2one( - related='company_id.intrastat_transport_id', readonly=False) + related="company_id.intrastat_transport_id", readonly=False + ) intrastat_region_id = fields.Many2one( - related='company_id.intrastat_region_id', readonly=False) + related="company_id.intrastat_region_id", readonly=False + ) intrastat_transaction_out_invoice = fields.Many2one( - related='company_id.intrastat_transaction_out_invoice', readonly=False) + related="company_id.intrastat_transaction_out_invoice", readonly=False + ) intrastat_transaction_out_refund = fields.Many2one( - related='company_id.intrastat_transaction_out_refund', readonly=False) + related="company_id.intrastat_transaction_out_refund", readonly=False + ) intrastat_transaction_in_invoice = fields.Many2one( - related='company_id.intrastat_transaction_in_invoice', readonly=False) + related="company_id.intrastat_transaction_in_invoice", readonly=False + ) intrastat_transaction_in_refund = fields.Many2one( - related='company_id.intrastat_transaction_in_refund', readonly=False) + related="company_id.intrastat_transaction_in_refund", readonly=False + ) intrastat_accessory_costs = fields.Boolean( - related='company_id.intrastat_accessory_costs', readonly=False) - country_id = fields.Many2one(related='company_id.country_id') - country_code = fields.Char(related='company_id.country_id.code') + related="company_id.intrastat_accessory_costs", readonly=False + ) + country_id = fields.Many2one(related="company_id.country_id") + country_code = fields.Char(related="company_id.country_id.code") diff --git a/intrastat_product/models/sale_order.py b/intrastat_product/models/sale_order.py index 443174a..eebbeb4 100644 --- a/intrastat_product/models/sale_order.py +++ b/intrastat_product/models/sale_order.py @@ -9,17 +9,19 @@ class SaleOrder(models.Model): _inherit = "sale.order" intrastat_transport_id = fields.Many2one( - comodel_name='intrastat.transport_mode', string='Transport Mode', - help="This information is used in Intrastat reports") + comodel_name="intrastat.transport_mode", + string="Transport Mode", + help="This information is used in Intrastat reports", + ) intrastat = fields.Selection( - string='Intrastat Declaration', - related='company_id.intrastat_dispatches') + string="Intrastat Declaration", related="company_id.intrastat_dispatches" + ) def _prepare_invoice(self): - '''Copy destination country to invoice''' + """Copy destination country to invoice""" vals = super(SaleOrder, self)._prepare_invoice() if self.intrastat_transport_id: - vals['intrastat_transport_id'] = self.intrastat_transport_id.id + vals["intrastat_transport_id"] = self.intrastat_transport_id.id if self.warehouse_id.region_id: - vals['src_dest_region_id'] = self.warehouse_id.region_id.id + vals["src_dest_region_id"] = self.warehouse_id.region_id.id return vals diff --git a/intrastat_product/models/stock_warehouse.py b/intrastat_product/models/stock_warehouse.py index cd7e683..7846e07 100644 --- a/intrastat_product/models/stock_warehouse.py +++ b/intrastat_product/models/stock_warehouse.py @@ -6,21 +6,22 @@ from odoo import fields, models class StockWarehouse(models.Model): - _inherit = 'stock.warehouse' + _inherit = "stock.warehouse" region_id = fields.Many2one( - comodel_name='intrastat.region', string='Intrastat Region') + comodel_name="intrastat.region", string="Intrastat Region" + ) class StockLocation(models.Model): - _inherit = 'stock.location' + _inherit = "stock.location" def get_intrastat_region(self): self.ensure_one() - locations = self.search([('id', 'parent_of', self.id)]) - warehouses = self.env['stock.warehouse'].search([ - ('lot_stock_id', 'in', locations.ids), - ('region_id', '!=', False)]) + locations = self.search([("id", "parent_of", self.id)]) + warehouses = self.env["stock.warehouse"].search( + [("lot_stock_id", "in", locations.ids), ("region_id", "!=", False)] + ) if warehouses: return warehouses[0].region_id return None diff --git a/intrastat_product/report/intrastat_product_report_xls.py b/intrastat_product/report/intrastat_product_report_xls.py index e333224..876fffe 100644 --- a/intrastat_product/report/intrastat_product_report_xls.py +++ b/intrastat_product/report/intrastat_product_report_xls.py @@ -4,192 +4,145 @@ import logging from odoo import models -from odoo.tools.translate import translate, _ +from odoo.tools.translate import _, translate _logger = logging.getLogger(__name__) -IR_TRANSLATION_NAME = 'intrastat.product.report' +IR_TRANSLATION_NAME = "intrastat.product.report" class IntrastatProductDeclarationXlsx(models.AbstractModel): - _name = 'report.intrastat_product.product_declaration_xls' - _inherit = 'report.report_xlsx.abstract' + _name = "report.intrastat_product.product_declaration_xls" + _inherit = "report.report_xlsx.abstract" def _(self, src): - lang = self.env.context.get('lang', 'en_US') - val = translate( - self.env.cr, IR_TRANSLATION_NAME, 'report', lang, src) or src + lang = self.env.context.get("lang", "en_US") + val = translate(self.env.cr, IR_TRANSLATION_NAME, "report", lang, src) or src return val def _get_template(self, declaration): template = { - 'product': { - 'header': { - 'type': 'string', - 'value': self._('Product'), + "product": { + "header": {"type": "string", "value": self._("Product")}, + "line": { + "value": self._render("line.product_id and line.product_id.name") }, - 'line': { - 'value': self._render( - "line.product_id and line.product_id.name"), - }, - 'width': 36, + "width": 36, }, - 'product_origin_country': { - 'header': { - 'type': 'string', - 'value': self._('Product C/O'), + "product_origin_country": { + "header": {"type": "string", "value": self._("Product C/O")}, + "line": { + "type": "string", + "value": self._render("line.product_origin_country_id.name or ''"), }, - 'line': { - 'type': 'string', - 'value': self._render( - "line.product_origin_country_id.name or ''"), - }, - 'width': 28, + "width": 28, }, - 'hs_code': { - 'header': { - 'type': 'string', - 'value': self._('Intrastat Code'), + "hs_code": { + "header": {"type": "string", "value": self._("Intrastat Code")}, + "line": { + "type": "string", + "value": self._render("line.hs_code_id.local_code"), }, - 'line': { - 'type': 'string', - 'value': self._render( - "line.hs_code_id.local_code"), - }, - 'width': 14, + "width": 14, }, - 'src_dest_country': { - 'header': { - 'type': 'string', - 'value': self._('Country of Origin/Destination'), + "src_dest_country": { + "header": { + "type": "string", + "value": self._("Country of Origin/Destination"), }, - 'line': { - 'type': 'string', - 'value': self._render( - "line.src_dest_country_id.name"), + "line": { + "type": "string", + "value": self._render("line.src_dest_country_id.name"), }, - 'width': 28, + "width": 28, }, - 'amount_company_currency': { - 'header': { - 'type': 'string', - 'value': self._('Fiscal Value'), - 'format': self.format_theader_yellow_right, + "amount_company_currency": { + "header": { + "type": "string", + "value": self._("Fiscal Value"), + "format": self.format_theader_yellow_right, }, - 'line': { - 'type': 'number', - 'value': self._render("line.amount_company_currency"), - 'format': self.format_tcell_amount_right, + "line": { + "type": "number", + "value": self._render("line.amount_company_currency"), + "format": self.format_tcell_amount_right, }, - 'width': 18, + "width": 18, }, - 'accessory_cost': { - 'header': { - 'type': 'string', - 'value': self._('Accessory Costs'), - 'format': self.format_theader_yellow_right, + "accessory_cost": { + "header": { + "type": "string", + "value": self._("Accessory Costs"), + "format": self.format_theader_yellow_right, }, - 'line': { - 'type': 'number', - 'value': self._render( - "line.amount_accessory_cost_company_currency"), - 'format': self.format_tcell_amount_right, + "line": { + "type": "number", + "value": self._render( + "line.amount_accessory_cost_company_currency" + ), + "format": self.format_tcell_amount_right, }, - 'width': 18, + "width": 18, }, - 'transaction': { - 'header': { - 'type': 'string', - 'value': self._('Intrastat Transaction'), - }, - 'line': { - 'value': self._render( - "line.transaction_id.display_name"), - }, - 'width': 36, + "transaction": { + "header": {"type": "string", "value": self._("Intrastat Transaction")}, + "line": {"value": self._render("line.transaction_id.display_name")}, + "width": 36, }, - 'weight': { - 'header': { - 'type': 'string', - 'value': self._('Weight'), - 'format': self.format_theader_yellow_right, + "weight": { + "header": { + "type": "string", + "value": self._("Weight"), + "format": self.format_theader_yellow_right, }, - 'line': { - 'type': 'number', - 'value': self._render( - "line.weight"), - 'format': self.format_tcell_amount_right, + "line": { + "type": "number", + "value": self._render("line.weight"), + "format": self.format_tcell_amount_right, }, - 'width': 18, + "width": 18, }, - 'suppl_unit_qty': { - 'header': { - 'type': 'string', - 'value': self._('Suppl. Unit Qty'), - 'format': self.format_theader_yellow_right, + "suppl_unit_qty": { + "header": { + "type": "string", + "value": self._("Suppl. Unit Qty"), + "format": self.format_theader_yellow_right, }, - 'line': { + "line": { # we don't specify a type here and rely on the # report_xlsx_helper type detection to use # write_string when suppl_unit_qty is zero - 'value': self._render( - "line.suppl_unit_qty or ''"), - 'format': self.format_tcell_amount_right, + "value": self._render("line.suppl_unit_qty or ''"), + "format": self.format_tcell_amount_right, }, - 'width': 18, + "width": 18, }, - 'suppl_unit': { - 'header': { - 'type': 'string', - 'value': self._('Suppl. Unit'), - }, - 'line': { - 'value': self._render( - "line.intrastat_unit_id.name or ''"), - }, - 'width': 14, + "suppl_unit": { + "header": {"type": "string", "value": self._("Suppl. Unit")}, + "line": {"value": self._render("line.intrastat_unit_id.name or ''")}, + "width": 14, }, - 'incoterm': { - 'header': { - 'type': 'string', - 'value': self._('Incoterm'), - }, - 'line': { - 'value': self._render("line.incoterm_id.name or ''"), - }, - 'width': 14, + "incoterm": { + "header": {"type": "string", "value": self._("Incoterm")}, + "line": {"value": self._render("line.incoterm_id.name or ''")}, + "width": 14, }, - 'transport': { - 'header': { - 'type': 'string', - 'value': self._('Transport Mode'), - }, - 'line': { - 'value': self._render("line.transport_id.name or ''"), - }, - 'width': 14, + "transport": { + "header": {"type": "string", "value": self._("Transport Mode")}, + "line": {"value": self._render("line.transport_id.name or ''")}, + "width": 14, }, - 'region': { - 'header': { - 'type': 'string', - 'value': self._('Intrastat Region'), - }, - 'line': { - 'value': self._render("line.region_id.name or ''"), - }, - 'width': 28, + "region": { + "header": {"type": "string", "value": self._("Intrastat Region")}, + "line": {"value": self._render("line.region_id.name or ''")}, + "width": 28, }, - 'invoice': { - 'header': { - 'type': 'string', - 'value': self._('Invoice'), - }, - 'line': { - 'value': self._render("line.invoice_id.number"), - }, - 'width': 18, + "invoice": { + "header": {"type": "string", "value": self._("Invoice")}, + "line": {"value": self._render("line.invoice_id.number")}, + "width": 18, }, } template.update(declaration._xls_template()) @@ -198,80 +151,86 @@ class IntrastatProductDeclarationXlsx(models.AbstractModel): def _get_ws_params(self, wb, data, declaration): template = self._get_template(declaration) - if self.env.context.get('computation_lines'): + if self.env.context.get("computation_lines"): wl = declaration._xls_computation_line_fields() - report = 'computation' + report = "computation" else: wl = declaration._xls_declaration_line_fields() - report = 'declaration' + report = "declaration" - title = self._get_title(declaration, report, title_format='normal') - title_short = self._get_title(declaration, report, - title_format='short') - sheet_name = title_short[:31].replace('/', '-') + title = self._get_title(declaration, report, title_format="normal") + title_short = self._get_title(declaration, report, title_format="short") + sheet_name = title_short[:31].replace("/", "-") params = { - 'ws_name': sheet_name, - 'generate_ws_method': '_intrastat_report', - 'title': title, - 'wanted_list': wl, - 'col_specs': template, + "ws_name": sheet_name, + "generate_ws_method": "_intrastat_report", + "title": title, + "wanted_list": wl, + "col_specs": template, } return [params] - def _get_title(self, declaration, report, title_format='normal'): + def _get_title(self, declaration, report, title_format="normal"): title = declaration.year_month - if title_format == 'normal': - if report == 'computation': - title += ' : ' + _('Computation Lines') + if title_format == "normal": + if report == "computation": + title += " : " + _("Computation Lines") else: - title += ' : ' + _('Declaration Lines') + title += " : " + _("Declaration Lines") return title def _report_title(self, ws, row_pos, ws_params, data, declaration): return self._write_ws_title(ws, row_pos, ws_params) - def _empty_report(self, ws, row_pos, ws_params, data, declaration, - report): - if report == 'computation': - lines = _('Computation Lines') + def _empty_report(self, ws, row_pos, ws_params, data, declaration, report): + if report == "computation": + lines = _("Computation Lines") else: - lines = _('Declaration Lines') - no_entries = _("No") + " " + lines + " " + _("for period %s") \ - % declaration.year_month + lines = _("Declaration Lines") + no_entries = ( + _("No") + " " + lines + " " + _("for period %s") % declaration.year_month + ) ws.write_string(row_pos, 0, no_entries, self.format_left_bold) def _intrastat_report(self, workbook, ws, ws_params, data, declaration): ws.set_landscape() ws.fit_to_pages(1, 0) - ws.set_header(self.xls_headers['standard']) - ws.set_footer(self.xls_footers['standard']) + ws.set_header(self.xls_headers["standard"]) + ws.set_footer(self.xls_footers["standard"]) self._set_column_width(ws, ws_params) row_pos = 0 row_pos = self._report_title(ws, row_pos, ws_params, data, declaration) - if self.env.context.get('computation_lines'): - report = 'computation' + if self.env.context.get("computation_lines"): + report = "computation" lines = declaration.computation_line_ids else: - report = 'declaration' + report = "declaration" lines = declaration.declaration_line_ids if not lines: - return self._empty_report( - ws, row_pos, ws_params, data, declaration, report) + return self._empty_report(ws, row_pos, ws_params, data, declaration, report) row_pos = self._write_line( - ws, row_pos, ws_params, col_specs_section='header', - default_format=self.format_theader_yellow_left) + ws, + row_pos, + ws_params, + col_specs_section="header", + default_format=self.format_theader_yellow_left, + ) ws.freeze_panes(row_pos, 0) for line in lines: row_pos = self._write_line( - ws, row_pos, ws_params, col_specs_section='line', - render_space={'line': line}, - default_format=self.format_tcell_left) + ws, + row_pos, + ws_params, + col_specs_section="line", + render_space={"line": line}, + default_format=self.format_tcell_left, + ) diff --git a/intrastat_product/views/account_invoice.xml b/intrastat_product/views/account_move.xml similarity index 87% rename from intrastat_product/views/account_invoice.xml rename to intrastat_product/views/account_move.xml index fda90a4..4fb65a7 100644 --- a/intrastat_product/views/account_invoice.xml +++ b/intrastat_product/views/account_move.xml @@ -1,12 +1,12 @@ - + intrastat.invoice.form - account.invoice - + account.move + - + + diff --git a/intrastat_product/views/intrastat_product_declaration.xml b/intrastat_product/views/intrastat_product_declaration.xml index 985b291..095f14d 100644 --- a/intrastat_product/views/intrastat_product_declaration.xml +++ b/intrastat_product/views/intrastat_product_declaration.xml @@ -87,7 +87,7 @@ intrastat.product.declaration.tree intrastat.product.declaration - + diff --git a/intrastat_product/views/intrastat_unit.xml b/intrastat_product/views/intrastat_unit.xml index d9d730b..073b7ca 100644 --- a/intrastat_product/views/intrastat_unit.xml +++ b/intrastat_product/views/intrastat_unit.xml @@ -10,60 +10,57 @@ - - intrastat.unit.form - intrastat.unit - -
-
- -
- - - - - -
-
+ + intrastat.unit.form + intrastat.unit + +
+ + + + + + + + +
- intrastat.unit.tree - intrastat.unit - - - - - - - + intrastat.unit.tree + intrastat.unit + + + + + + + - intrastat.unit.search - intrastat.unit - - - - - - - - - + intrastat.unit.search + intrastat.unit + + + + + + + + + - Supplementary Units - intrastat.unit - tree,form + Supplementary Units + intrastat.unit + tree,form