Skip to content

Commit

Permalink
Merge PR #3463 into 14.0
Browse files Browse the repository at this point in the history
Signed-off-by sergiocorato
  • Loading branch information
OCA-git-bot committed Feb 16, 2024
2 parents d874afb + 87bb24b commit caade57
Show file tree
Hide file tree
Showing 4 changed files with 26 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 @@ -258,6 +257,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 @@ -273,7 +276,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 @@ -295,7 +303,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 @@ -120,7 +125,8 @@ def create(self, values):
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
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ def setUp(self):
self.env.company.fatturapa_fiscal_position_id = self.env.ref(
"l10n_it_fatturapa.fatturapa_RF01"
).id
self.env.company.declaration_yearly_limit_ids = [
(0, 0, {"year": 2016, "limit_amount": 500})
]

self.env.ref("product.decimal_product_uom").digits = 3
self.env.ref("uom.product_uom_unit").name = "Unit(s)"
Expand Down

0 comments on commit caade57

Please sign in to comment.