Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[14.0][IMP] Big simplification, update and cleanup #198

Closed
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
2 changes: 1 addition & 1 deletion intrastat_product/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from . import res_company
from . import res_config_settings
from . import res_partner
from . import account_move
from . import hs_code
Expand All @@ -10,3 +9,4 @@
from . import intrastat_unit
from . import sale_order
from . import stock_warehouse
from . import account_fiscal_position
44 changes: 44 additions & 0 deletions intrastat_product/models/account_fiscal_position.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# 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",
help="Odoo uses the intrastat transaction of the invoice. "
"If not set, Odoo uses the default intrastat transaction of "
"the fiscal position of the invoice. "
"If not set, Odoo uses the default intrastat transaction of the company.",
)
intrastat_out_refund_transaction_id = fields.Many2one(
comodel_name="intrastat.transaction",
string="Default Intrastat Transaction for Customer Refunds",
help="Odoo uses the intrastat transaction of the invoice. "
"If not set, Odoo uses the default intrastat transaction of "
"the fiscal position of the invoice. "
"If not set, Odoo uses the default intrastat transaction of the company.",
)
intrastat_in_invoice_transaction_id = fields.Many2one(
comodel_name="intrastat.transaction",
string="Default Intrastat Transaction For Supplier Invoices",
help="Odoo uses the intrastat transaction of the invoice. "
"If not set, Odoo uses the default intrastat transaction of "
"the fiscal position of the invoice. "
"If not set, Odoo uses the default intrastat transaction of the company.",
)
intrastat_in_refund_transaction_id = fields.Many2one(
comodel_name="intrastat.transaction",
string="Default Intrastat Transaction For Supplier Refunds",
help="Odoo uses the intrastat transaction of the invoice. "
"If not set, Odoo uses the default intrastat transaction of "
"the fiscal position of the invoice. "
"If not set, Odoo uses the default intrastat transaction of the company.",
)
# field used to show/hide fields in country-specific modules
company_country_code = fields.Char(related="company_id.partner_id.country_id.code")
44 changes: 2 additions & 42 deletions intrastat_product/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class AccountMove(models.Model):
src_dest_region_id = fields.Many2one(
comodel_name="intrastat.region",
string="Origin/Destination Region",
default=lambda self: self._default_src_dest_region_id(),
default=lambda self: self.env.company.intrastat_region_id,
help="Origin region for dispatches, destination region for "
"arrivals. This field is used for the Intrastat Declaration.",
ondelete="restrict",
Expand All @@ -55,10 +55,6 @@ def _compute_src_dest_country_id(self):
country = inv.company_id.country_id
inv.src_dest_country_id = country.id

@api.model
def _default_src_dest_region_id(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This hook was done for a reason, so it's not good to remove it.

return self.env.company.intrastat_region_id

def compute_intrastat_lines(self):
"""
Compute the Intrastat Lines so that they can be modified
Expand Down Expand Up @@ -93,22 +89,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 +195,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 All @@ -236,18 +211,3 @@ def _onchange_move_id(self):
("id", "not in", moves.mapped("intrastat_line_ids.invoice_line_id").ids),
]
return {"domain": {"invoice_line_id": dom}}

@api.model
def create(self, vals):
self._format_vals(vals)
return super().create(vals)

def write(self, vals):
self._format_vals(vals)
return super().write(vals)

def _format_vals(self, vals):
if "product_origin_country_code" in vals:
vals["product_origin_country_code"] = (
vals["product_origin_country_code"].upper().strip()
)
Loading