mirror of
https://github.com/OCA/intrastat-extrastat.git
synced 2025-02-16 17:13:41 +02:00
intrastat_product: default intrastat transaction on fiscal position AND company
Odoo uses, by order of priority: 1) intrastat transaction of the invoice 2) default intrastat transaction of the fiscal position of the invoice 3) default intrastat transaction of the company
This commit is contained in:
@@ -11,18 +11,34 @@ class AccountFiscalPosition(models.Model):
|
||||
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.country_id.code")
|
||||
|
||||
@@ -200,16 +200,21 @@ class IntrastatProductDeclaration(models.Model):
|
||||
|
||||
@api.depends("declaration_line_ids.amount_company_currency")
|
||||
def _compute_numbers(self):
|
||||
rg_res = self.env['intrastat.product.declaration.line'].read_group(
|
||||
[('parent_id', 'in', self.ids)],
|
||||
['parent_id', 'amount_company_currency:sum'],
|
||||
['parent_id'])
|
||||
mapped_data = dict(
|
||||
[(x['parent_id'][0],
|
||||
{'num_decl_lines': x['parent_id_count'], 'total_amount': x['amount_company_currency']}) for x in rg_res])
|
||||
rg_res = self.env["intrastat.product.declaration.line"].read_group(
|
||||
[("parent_id", "in", self.ids)],
|
||||
["parent_id", "amount_company_currency:sum"],
|
||||
["parent_id"],
|
||||
)
|
||||
mapped_data = {
|
||||
x["parent_id"][0]: {
|
||||
"num_decl_lines": x["parent_id_count"],
|
||||
"total_amount": x["amount_company_currency"],
|
||||
}
|
||||
for x in rg_res
|
||||
}
|
||||
for this in self:
|
||||
this.num_decl_lines = mapped_data.get(this.id, {}).get('num_decl_lines', 0)
|
||||
this.total_amount = mapped_data.get(this.id, {}).get('total_amount', 0)
|
||||
this.num_decl_lines = mapped_data.get(this.id, {}).get("num_decl_lines", 0)
|
||||
this.total_amount = mapped_data.get(this.id, {}).get("total_amount", 0)
|
||||
|
||||
@api.constrains("year")
|
||||
def _check_year(self):
|
||||
@@ -303,18 +308,18 @@ class IntrastatProductDeclaration(models.Model):
|
||||
def _get_intrastat_transaction(self, inv_line, notedict):
|
||||
invoice = inv_line.move_id
|
||||
transaction = invoice.intrastat_transaction_id
|
||||
if not transaction:
|
||||
fieldmap = {
|
||||
"out_invoice": "intrastat_out_invoice_transaction_id",
|
||||
"out_refund": "intrastat_out_refund_transaction_id",
|
||||
"in_invoice": "intrastat_in_invoice_transaction_id",
|
||||
"in_refund": "intrastat_in_refund_transaction_id",
|
||||
}
|
||||
if not transaction and invoice.move_type in fieldmap:
|
||||
# as we have searched with intrastat_fiscal_position = True
|
||||
# we should always have a fiscal position on the invoice
|
||||
fp = invoice.fiscal_position_id
|
||||
if invoice.move_type == "out_invoice":
|
||||
transaction = fp.intrastat_out_invoice_transaction_id
|
||||
elif invoice.move_type == "out_refund":
|
||||
transaction = fp.intrastat_out_refund_transaction_id
|
||||
elif invoice.move_type == "in_invoice":
|
||||
transaction = fp.intrastat_in_invoice_transaction_id
|
||||
elif invoice.move_type == "in_refund":
|
||||
transaction = fp.intrastat_in_refund_transaction_id
|
||||
transaction = invoice.fiscal_position_id[fieldmap[invoice.move_type]]
|
||||
if not transaction and invoice.move_type in fieldmap:
|
||||
transaction = invoice.company_id[fieldmap[invoice.move_type]]
|
||||
if not transaction:
|
||||
line_notes = [
|
||||
_(
|
||||
|
||||
@@ -35,6 +35,38 @@ class ResCompany(models.Model):
|
||||
intrastat_region_id = fields.Many2one(
|
||||
comodel_name="intrastat.region", string="Default Intrastat Region"
|
||||
)
|
||||
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.",
|
||||
)
|
||||
intrastat_accessory_costs = fields.Boolean(
|
||||
string="Include Accessory Costs in Fiscal Value of Product"
|
||||
)
|
||||
|
||||
@@ -21,6 +21,18 @@ class ResConfigSettings(models.TransientModel):
|
||||
intrastat_region_id = fields.Many2one(
|
||||
related="company_id.intrastat_region_id", readonly=False
|
||||
)
|
||||
intrastat_out_invoice_transaction_id = fields.Many2one(
|
||||
related="company_id.intrastat_out_invoice_transaction_id", readonly=False
|
||||
)
|
||||
intrastat_out_refund_transaction_id = fields.Many2one(
|
||||
related="company_id.intrastat_out_refund_transaction_id", readonly=False
|
||||
)
|
||||
intrastat_in_invoice_transaction_id = fields.Many2one(
|
||||
related="company_id.intrastat_in_invoice_transaction_id", readonly=False
|
||||
)
|
||||
intrastat_in_refund_transaction_id = fields.Many2one(
|
||||
related="company_id.intrastat_in_refund_transaction_id", readonly=False
|
||||
)
|
||||
intrastat_accessory_costs = fields.Boolean(
|
||||
related="company_id.intrastat_accessory_costs", readonly=False
|
||||
)
|
||||
|
||||
@@ -311,8 +311,12 @@
|
||||
optional="show"
|
||||
attrs="{'column_invisible': [('parent.reporting_level', '!=', 'extended')]}"
|
||||
/>
|
||||
<field name="amount_company_currency" />
|
||||
<field name="amount_accessory_cost_company_currency" optional="show" />
|
||||
<field name="amount_company_currency" sum="1" />
|
||||
<field
|
||||
name="amount_accessory_cost_company_currency"
|
||||
optional="show"
|
||||
sum="1"
|
||||
/>
|
||||
<field name="transaction_id" />
|
||||
<field
|
||||
name="weight"
|
||||
@@ -450,7 +454,7 @@
|
||||
attrs="{'column_invisible': [('parent.reporting_level', '!=', 'extended')]}"
|
||||
optional="show"
|
||||
/>
|
||||
<field name="amount_company_currency" />
|
||||
<field name="amount_company_currency" sum="1" />
|
||||
<field name="transaction_id" />
|
||||
<field
|
||||
name="weight"
|
||||
|
||||
@@ -32,6 +32,37 @@
|
||||
<label for="intrastat_transport_id" class="col-md-5" />
|
||||
<field name="intrastat_transport_id" />
|
||||
</div>
|
||||
<div class="row">
|
||||
<label
|
||||
for="intrastat_out_invoice_transaction_id"
|
||||
class="col-md-5"
|
||||
/>
|
||||
<field name="intrastat_out_invoice_transaction_id" />
|
||||
</div>
|
||||
<div class="row">
|
||||
<label
|
||||
for="intrastat_out_refund_transaction_id"
|
||||
class="col-md-5"
|
||||
/>
|
||||
<field name="intrastat_out_refund_transaction_id" />
|
||||
</div>
|
||||
<div class="row">
|
||||
<label
|
||||
for="intrastat_in_invoice_transaction_id"
|
||||
class="col-md-5"
|
||||
/>
|
||||
<field name="intrastat_in_invoice_transaction_id" />
|
||||
</div>
|
||||
<div
|
||||
class="row"
|
||||
attrs="{'invisible': [('country_code', 'in', ['FR'])]}"
|
||||
>
|
||||
<label
|
||||
for="intrastat_in_refund_transaction_id"
|
||||
class="col-md-5"
|
||||
/>
|
||||
<field name="intrastat_in_refund_transaction_id" />
|
||||
</div>
|
||||
<div
|
||||
class="row"
|
||||
attrs="{'invisible': [('country_code', 'not in', ['BE'])]}"
|
||||
|
||||
Reference in New Issue
Block a user