Skip to content

Commit

Permalink
[FIX] l10n_it_declaration_of_intent: permit to add dichiarazione.inte…
Browse files Browse the repository at this point in the history
…nto records that exceeds the limit_amount of dichiarazione.intento.yearly.limit
  • Loading branch information
fredzamoabg authored and Borruso committed Jul 7, 2023
1 parent d7baa4c commit 34c3cbc
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
13 changes: 10 additions & 3 deletions l10n_it_declaration_of_intent/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@


class AccountMove(models.Model):

_inherit = "account.move"

declaration_of_intent_ids = fields.Many2many(
Expand Down Expand Up @@ -253,6 +252,10 @@ def check_declarations_amounts(self, declarations):

def get_declaration_residual_amounts(self, declarations):
"""Get residual amount for every `declarations`."""
plafond = self.env.user.company_id.declaration_yearly_limit_ids.filtered(
lambda r: r.year == str(fields.first(declarations).date_start.year)
)
available_plafond = plafond.limit_amount - plafond.actual_used_amount
declarations_amounts = {}
# If the tax amount is 0, then there is no line representing the tax
# so there will be no line having tax_line_id.
Expand All @@ -268,7 +271,12 @@ def get_declaration_residual_amounts(self, declarations):

for declaration in declarations:
if declaration.id not in declarations_amounts:
declarations_amounts[declaration.id] = declaration.available_amount
if declaration.available_amount > available_plafond:
declarations_amounts[declaration.id] = available_plafond
else:
declarations_amounts[
declaration.id
] = declaration.available_amount
if any(tax in declaration.taxes_ids for tax in tax_line.tax_ids):
declarations_amounts[declaration.id] -= amount
for declaration in declarations:
Expand All @@ -290,7 +298,6 @@ def button_cancel(self):


class AccountMoveLine(models.Model):

_inherit = "account.move.line"

force_declaration_of_intent_id = fields.Many2one(
Expand Down
17 changes: 11 additions & 6 deletions l10n_it_declaration_of_intent/models/declaration.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,21 @@


class DeclarationOfIntentYearlyLimit(models.Model):

_name = "l10n_it_declaration_of_intent.yearly_limit"
_description = "Yearly limit for declarations"
_order = "company_id, year desc"
_rec_name = "year"

company_id = fields.Many2one("res.company", string="Company")
year = fields.Char(required=True)
limit_amount = fields.Float()
used_amount = fields.Float(compute="_compute_used_amount")
limit_amount = fields.Float(string="Plafond")
# TODO align terms: used_amount > issued_declarations
used_amount = fields.Float(
string="Issued Declarations", compute="_compute_used_amount"
)
actual_used_amount = fields.Float(
string="Actual Used Amount", compute="_compute_used_amount"
)

def _compute_used_amount(self):
for record in self:
Expand All @@ -31,10 +36,10 @@ def _compute_used_amount(self):
]
)
record.used_amount = sum([d.limit_amount for d in declarations])
record.actual_used_amount = sum([d.used_amount for d in declarations])


class DeclarationOfIntent(models.Model):

_name = "l10n_it_declaration_of_intent.declaration"
_description = "Declaration of intent"
_order = "date_start desc,date_end desc"
Expand Down Expand Up @@ -121,7 +126,8 @@ def create(self, vals_list):
sum([d.limit_amount for d in declarations]) + values["limit_amount"]
)
if actual_limit_total > plafond.limit_amount:
raise UserError(_("Total of documents exceed yearly limit"))
if plafond.limit_amount < plafond.actual_used_amount:
raise UserError(_("Total of documents exceed yearly limit"))
# ----- Assign a number to declaration
if values and not values.get("number", ""):
values["number"] = self.env["ir.sequence"].next_by_code(
Expand Down Expand Up @@ -255,7 +261,6 @@ def get_all_for_partner(self, type_d=None, partner_id=False, ignore_state=False)


class DeclarationOfIntentLine(models.Model):

_name = "l10n_it_declaration_of_intent.declaration_line"
_description = "Details of declaration of intent"

Expand Down
3 changes: 2 additions & 1 deletion l10n_it_declaration_of_intent/views/company_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
<field name="inherit_id" ref="base.view_company_form" />
<field name="arch" type="xml">
<xpath expr="//page[last()]" position="after">
<page string="Declarations of intent">
<page string="Exporter Plafond">
<field name="declaration_yearly_limit_ids">
<tree editable="top">
<field name="year" />
<field name="limit_amount" />
<field name="used_amount" />
<field name="actual_used_amount" />
</tree>
</field>
</page>
Expand Down

0 comments on commit 34c3cbc

Please sign in to comment.