Skip to content

Commit

Permalink
IMP l10n_it_reverse_charge adding original_purchase_tax_id to allow m…
Browse files Browse the repository at this point in the history
…apping of 3 documents: original supplier invoice (intra/extra), supplier self invoice, customer self invoice
  • Loading branch information
eLBati committed May 27, 2022
1 parent c5632d8 commit 4870e27
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 19 deletions.
18 changes: 13 additions & 5 deletions l10n_it_reverse_charge/models/account_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,9 +390,6 @@ def generate_self_invoice(self):

def generate_supplier_self_invoice(self):
rc_type = self.fiscal_position_id.rc_type_id
if not len(rc_type.tax_ids) == 1:
raise UserError(_(
"Can't find 1 tax mapping for %s" % rc_type.name))
if not self.rc_self_purchase_invoice_id:
supplier_invoice = self.copy()
else:
Expand All @@ -410,8 +407,19 @@ def generate_supplier_self_invoice(self):
supplier_invoice.partner_id = rc_type.partner_id.id
supplier_invoice.journal_id = rc_type.supplier_journal_id.id
for inv_line in supplier_invoice.invoice_line_ids:
inv_line.invoice_line_tax_ids = [
(6, 0, [rc_type.tax_ids[0].purchase_tax_id.id])]
line_tax_ids = inv_line.invoice_line_tax_ids
tax_ids = list()
for tax_mapping in rc_type.tax_ids:
for line_tax_id in line_tax_ids:
if tax_mapping.original_purchase_tax_id == line_tax_id:
tax_ids.append(tax_mapping.purchase_tax_id.id)
if not tax_ids:
raise UserError(_("Tax code used is not a RC tax.\nCan't "
"find tax mapping"))
if line_tax_ids:
inv_line.invoice_line_tax_ids = [
(6, False, tax_ids)]

inv_line.account_id = rc_type.transitory_account_id.id
self.rc_self_purchase_invoice_id = supplier_invoice.id

Expand Down
18 changes: 5 additions & 13 deletions l10n_it_reverse_charge/models/account_rc_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
# Copyright 2017 Lorenzo Battistini - Agile Business Group
# Copyright 2017 Marco Calcagni - Dinamiche Aziendali srl

from odoo import fields, models, _, api
from odoo.exceptions import ValidationError
from odoo import fields, models


class AccountRCTypeTax(models.Model):
Expand All @@ -16,6 +15,10 @@ class AccountRCTypeTax(models.Model):
string='RC type',
required=True,
ondelete='cascade')
original_purchase_tax_id = fields.Many2one(
'account.tax',
string='Original Purchase Tax',
required=False)
purchase_tax_id = fields.Many2one(
'account.tax',
string='Purchase Tax',
Expand Down Expand Up @@ -85,14 +88,3 @@ class AccountRCType(models.Model):
company_id = fields.Many2one(
'res.company', string='Company', required=True,
default=lambda self: self.env.user.company_id)

@api.multi
@api.constrains('with_supplier_self_invoice', 'tax_ids')
def _check_tax_ids(self):
for rctype in self:
if rctype.with_supplier_self_invoice and len(rctype.tax_ids) > 1:
raise ValidationError(_(
'When "With additional supplier self invoice" you must set'
' only one tax mapping line: only 1 tax per invoice is '
'supported'
))
1 change: 1 addition & 0 deletions l10n_it_reverse_charge/tests/rc_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ def _create_rc_type_taxes(self):

self.rc_type_tax_eeu = rc_type_tax_model.create({
'rc_type_id': self.rc_type_eeu.id,
'original_purchase_tax_id': self.tax_0_pur.id,
'purchase_tax_id': self.tax_22ae.id,
'sale_tax_id': self.tax_22ve.id
})
Expand Down
2 changes: 1 addition & 1 deletion l10n_it_reverse_charge/tests/test_rc.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def test_extra_EU(self):
'invoice_id': invoice.id,
'product_id': self.sample_product.id,
'price_unit': 100,
'invoice_line_tax_ids': [(4, self.tax_22ai.id, 0)]}
'invoice_line_tax_ids': [(4, self.tax_0_pur.id, 0)]}
invoice_line = self.invoice_line_model.create(invoice_line_vals)
invoice_line.onchange_invoice_line_tax_id()
invoice.compute_taxes()
Expand Down
1 change: 1 addition & 0 deletions l10n_it_reverse_charge/views/account_rc_type_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
'readonly': [('method', '!=', 'selfinvoice')],
'required': [('method', '=', 'selfinvoice')]}">
<tree string="Tax Mapping" editable="bottom">
<field name="original_purchase_tax_id" />
<field name="purchase_tax_id" />
<field name="sale_tax_id" />
</tree>
Expand Down

0 comments on commit 4870e27

Please sign in to comment.