Skip to content

Commit

Permalink
[IMP] Big simplification, update and cleanup
Browse files Browse the repository at this point in the history
This commit aims at removing the over-complexity of intrastat modules
while increasing simplicity/usability for users.

- Move default intrastat transaction from res.company to account.fiscal.position to add su
pport for B2C (and not just B2B)
- improve usability: auto-generate declaration lines and XML export when
going from draft to done. Auto-delete declaration lines and XML export
when going from done to draft (and add confirmation pop-up).
- declaration lines are now readonly. Only computation lines can be created/edited manuall
y
- add field region_code on computation lines and declaration lines.
Remove region_id on declaration lines. This change allows big
simplification in some localization modules such as
l10n_fr_intrastat_product.
- simplify Brexit implementation. Northern Ireland is important, but we
can't afford to have so many lines of code and add a field on
product.template (origin_state_id) for a territory of 1.9 million
inhabitants! This is too costly to maintain and too complex for users.
- improve default visibility of fields when reporting_level = 'standard'
- add support for weight calculation from uom categories other than
units and weight, supposing that the 'weight' field on product.template
is the weight per uom of the product
- add EU companies from several different countries in demo data with valid VAT numbers
  • Loading branch information
alexis-via committed Nov 4, 2022
1 parent 6f5edb8 commit 766d016
Show file tree
Hide file tree
Showing 21 changed files with 506 additions and 560 deletions.
56 changes: 52 additions & 4 deletions intrastat_base/demo/intrastat_demo.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,64 @@
<?xml version="1.0" encoding="utf-8" ?>
<!--
Copyright 2011-2020 Akretion France (http://www.akretion.com/)
Copyright 2011-2022 Akretion France (http://www.akretion.com/)
@author: Alexis de Lattre <alexis.delattre@akretion.com>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->
<odoo noupdate="1">
<record id="base.main_partner" model="res.partner">
<field name="vat">FR58441019213</field>
</record>
<record id="base.res_partner_2" model="res.partner">
<!-- Deco Addict -->
<field name="vat">BE0884025633</field>
<!-- Create a few partners from several EU countries
with real/valid VAT number -->
<record id="noviat" model="res.partner">
<field name="name">Noviat</field>
<field name="is_company">1</field>
<field name="website">https://www.noviat.com</field>
<field name="street">Avenue de Rusatiralaan 1</field>
<field name="city">Ganshoren</field>
<field name="zip">1083</field>
<field name="country_id" ref="base.be" />
<field name="vat">BE0820512013</field>
</record>
<record id="acsone" model="res.partner">
<field name="name">Acsone</field>
<field name="is_company">1</field>
<field name="website">https://www.acsone.eu</field>
<field name="street">Drève Richelle, 167</field>
<field name="city">Waterloo</field>
<field name="zip">1410</field>
<field name="country_id" ref="base.be" />
<field name="vat">BE0835207216</field>
</record>
<record id="tecnativa" model="res.partner">
<field name="name">Tecnativa</field>
<field name="is_company">1</field>
<field name="website">https://www.tecnativa.com</field>
<field name="street">Calle Tormos 1-A, 25</field>
<field name="city">Alicante</field>
<field name="zip">03008</field>
<field name="country_id" ref="base.es" />
<field name="vat">ESB87530432</field>
</record>
<record id="forgeflow" model="res.partner">
<field name="name">ForgeFlow</field>
<field name="is_company">1</field>
<field name="website">https://www.forgeflow.com</field>
<field name="street">Rosselló 319, 6-1</field>
<field name="city">Barcelona</field>
<field name="zip">08037</field>
<field name="country_id" ref="base.es" />
<field name="vat">ESB66676008</field>
</record>
<record id="akretion_france" model="res.partner">
<field name="name">Akretion France</field>
<field name="is_company">1</field>
<field name="website">https://www.akretion.com</field>
<field name="street">27 rue Henri Rolland</field>
<field name="city">Villeurbanne</field>
<field name="zip">69100</field>
<field name="country_id" ref="base.fr" />
<field name="vat">FR86792377731</field>
</record>
<record id="shipping_costs_exclude" model="product.product">
<field name="name">Shipping costs</field>
Expand Down
1 change: 0 additions & 1 deletion intrastat_base/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@
from . import account_fiscal_position
from . import account_fiscal_position_template
from . import account_move
from . import res_partner
67 changes: 0 additions & 67 deletions intrastat_base/models/res_partner.py

This file was deleted.

1 change: 1 addition & 0 deletions intrastat_product/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"views/intrastat_product_declaration.xml",
"views/res_config_settings.xml",
"views/res_partner_view.xml",
"views/account_fiscal_position.xml",
"views/account_move.xml",
"views/sale_order.xml",
"views/stock_warehouse.xml",
Expand Down
1 change: 1 addition & 0 deletions intrastat_product/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@
from . import intrastat_unit
from . import sale_order
from . import stock_warehouse
from . import account_fiscal_position
28 changes: 28 additions & 0 deletions intrastat_product/models/account_fiscal_position.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright 2022 Akretion France (http://www.akretion.com/)
# @author: <alexis.delattre@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import fields, models


class AccountFiscalPosition(models.Model):
_inherit = "account.fiscal.position"

intrastat_out_invoice_transaction_id = fields.Many2one(
comodel_name="intrastat.transaction",
string="Default Intrastat Transaction For Customer Invoice",
)
intrastat_out_refund_transaction_id = fields.Many2one(
comodel_name="intrastat.transaction",
string="Default Intrastat Transaction for Customer Refunds",
)
intrastat_in_invoice_transaction_id = fields.Many2one(
comodel_name="intrastat.transaction",
string="Default Intrastat Transaction For Supplier Invoices",
)
intrastat_in_refund_transaction_id = fields.Many2one(
comodel_name="intrastat.transaction",
string="Default Intrastat Transaction For Supplier Refunds",
)
# field used to show/hide fields in country-specific modules
company_country_code = fields.Char(related="company_id.country_id.code")
23 changes: 1 addition & 22 deletions intrastat_product/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,22 +93,13 @@ def _get_intrastat_line_vals(self, line):
if not hs_code:
return vals
weight, qty = decl_model._get_weight_and_supplunits(line, hs_code, notedict)
product_country = line.product_id.origin_country_id
product_state = line.product_id.origin_state_id
country = product_country or product_state.country_id
product_origin_country_code = "QU"
if country:
product_origin_country_code = self.env[
"res.partner"
]._get_intrastat_country_code(product_country, product_state)
vals.update(
{
"invoice_line_id": line.id,
"hs_code_id": hs_code.id,
"transaction_weight": weight,
"transaction_suppl_unit_qty": qty,
"product_origin_country_id": line.product_id.origin_country_id.id,
"product_origin_country_code": product_origin_country_code,
}
)
return vals
Expand Down Expand Up @@ -208,22 +199,10 @@ class AccountMoveIntrastatLine(models.Model):
transaction_weight = fields.Integer(
help="Transaction weight in Kg: Quantity x Product Weight"
)
# product_origin_country_id is replaced by product_origin_country_code
# this field should be dropped once the localisation modules have been
# adapted accordingly
product_origin_country_id = fields.Many2one(
comodel_name="res.country",
string="Country of Origin",
help="Country of origin of the product i.e. product " "'made in ____'.",
)
product_origin_country_code = fields.Char(
string="Country of Origin of the Product",
size=2,
required=True,
default="QU",
help="2 digit code of country of origin of the product except for the UK.\n"
"Specify 'XI' for UK Northern Ireland and 'XU' for rest of the UK.\n"
"Specify 'QU' when the country is unknown.\n",
help="Country of origin of the product i.e. product " "'made in ____'.",
)

@api.onchange("invoice_line_id")
Expand Down
Loading

0 comments on commit 766d016

Please sign in to comment.