Skip to content

Commit

Permalink
Merge PR #2690 into 14.0
Browse files Browse the repository at this point in the history
Signed-off-by rvalyi
  • Loading branch information
OCA-git-bot committed Oct 11, 2023
2 parents 257e2e0 + 51c1e87 commit c5ed4a7
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 33 deletions.
83 changes: 50 additions & 33 deletions l10n_br_fiscal/models/document_fiscal_mixin_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ def _get_amount_lines(self):
"""Get object lines instaces used to compute fields"""
return self.mapped("fiscal_line_ids")

def _get_product_amount_lines(self):
"""Get object lines instaces used to compute fields"""
fiscal_line_ids = self._get_amount_lines()
return fiscal_line_ids.filtered(lambda l: l.product_id.type != "service")

@api.model
def _get_amount_fields(self):
"""Get all fields with 'amount_' prefix"""
Expand Down Expand Up @@ -102,38 +107,42 @@ def _onchange_fiscal_operation_id(self):
self.comment_ids = self.fiscal_operation_id.comment_ids

def _inverse_amount_freight(self):
for record in self.filtered(lambda doc: doc._get_amount_lines()):
for record in self.filtered(lambda doc: doc._get_product_amount_lines()):
if (
record.delivery_costs == "total"
or record.force_compute_delivery_costs_by_total
):

amount_freight_value = record.amount_freight_value
if all(record._get_amount_lines().mapped("freight_value")):
if all(record._get_product_amount_lines().mapped("freight_value")):
amount_freight_old = sum(
record._get_amount_lines().mapped("freight_value")
record._get_product_amount_lines().mapped("freight_value")
)
for line in record._get_amount_lines()[:-1]:
for line in record._get_product_amount_lines()[:-1]:
line.freight_value = amount_freight_value * (
line.freight_value / amount_freight_old
)
record._get_amount_lines()[
record._get_product_amount_lines()[
-1
].freight_value = amount_freight_value - sum(
line.freight_value for line in record._get_amount_lines()[:-1]
line.freight_value
for line in record._get_product_amount_lines()[:-1]
)
else:
amount_total = sum(record._get_amount_lines().mapped("price_gross"))
for line in record._get_amount_lines()[:-1]:
amount_total = sum(
record._get_product_amount_lines().mapped("price_gross")
)
for line in record._get_product_amount_lines()[:-1]:
line.freight_value = amount_freight_value * (
line.price_gross / amount_total
)
record._get_amount_lines()[
record._get_product_amount_lines()[
-1
].freight_value = amount_freight_value - sum(
line.freight_value for line in record._get_amount_lines()[:-1]
line.freight_value
for line in record._get_product_amount_lines()[:-1]
)
for line in record._get_amount_lines():
for line in record._get_product_amount_lines():
line._onchange_fiscal_taxes()
record._fields["amount_total"].compute_value(record)
record.write(
Expand All @@ -146,38 +155,42 @@ def _inverse_amount_freight(self):
)

def _inverse_amount_insurance(self):
for record in self.filtered(lambda doc: doc._get_amount_lines()):
for record in self.filtered(lambda doc: doc._get_product_amount_lines()):
if (
record.delivery_costs == "total"
or record.force_compute_delivery_costs_by_total
):

amount_insurance_value = record.amount_insurance_value
if all(record._get_amount_lines().mapped("insurance_value")):
if all(record._get_product_amount_lines().mapped("insurance_value")):
amount_insurance_old = sum(
record._get_amount_lines().mapped("insurance_value")
record._get_product_amount_lines().mapped("insurance_value")
)
for line in record._get_amount_lines()[:-1]:
for line in record._get_product_amount_lines()[:-1]:
line.insurance_value = amount_insurance_value * (
line.insurance_value / amount_insurance_old
)
record._get_amount_lines()[
record._get_product_amount_lines()[
-1
].insurance_value = amount_insurance_value - sum(
line.insurance_value for line in record._get_amount_lines()[:-1]
line.insurance_value
for line in record._get_product_amount_lines()[:-1]
)
else:
amount_total = sum(record._get_amount_lines().mapped("price_gross"))
for line in record._get_amount_lines()[:-1]:
amount_total = sum(
record._get_product_amount_lines().mapped("price_gross")
)
for line in record._get_product_amount_lines()[:-1]:
line.insurance_value = amount_insurance_value * (
line.price_gross / amount_total
)
record._get_amount_lines()[
record._get_product_amount_lines()[
-1
].insurance_value = amount_insurance_value - sum(
line.insurance_value for line in record._get_amount_lines()[:-1]
line.insurance_value
for line in record._get_product_amount_lines()[:-1]
)
for line in record._get_amount_lines():
for line in record._get_product_amount_lines():
line._onchange_fiscal_taxes()
record._fields["amount_total"].compute_value(record)
record.write(
Expand All @@ -190,37 +203,41 @@ def _inverse_amount_insurance(self):
)

def _inverse_amount_other(self):
for record in self.filtered(lambda doc: doc._get_amount_lines()):
for record in self.filtered(lambda doc: doc._get_product_amount_lines()):
if (
record.delivery_costs == "total"
or record.force_compute_delivery_costs_by_total
):
amount_other_value = record.amount_other_value
if all(record._get_amount_lines().mapped("other_value")):
if all(record._get_product_amount_lines().mapped("other_value")):
amount_other_old = sum(
record._get_amount_lines().mapped("other_value")
record._get_product_amount_lines().mapped("other_value")
)
for line in record._get_amount_lines()[:-1]:
for line in record._get_product_amount_lines()[:-1]:
line.other_value = amount_other_value * (
line.other_value / amount_other_old
)
record._get_amount_lines()[
record._get_product_amount_lines()[
-1
].other_value = amount_other_value - sum(
line.other_value for line in record._get_amount_lines()[:-1]
line.other_value
for line in record._get_product_amount_lines()[:-1]
)
else:
amount_total = sum(record._get_amount_lines().mapped("price_gross"))
for line in record._get_amount_lines()[:-1]:
amount_total = sum(
record._get_product_amount_lines().mapped("price_gross")
)
for line in record._get_product_amount_lines()[:-1]:
line.other_value = amount_other_value * (
line.price_gross / amount_total
)
record._get_amount_lines()[
record._get_product_amount_lines()[
-1
].other_value = amount_other_value - sum(
line.other_value for line in record._get_amount_lines()[:-1]
line.other_value
for line in record._get_product_amount_lines()[:-1]
)
for line in record._get_amount_lines():
for line in record._get_product_amount_lines():
line._onchange_fiscal_taxes()
record._fields["amount_total"].compute_value(record)
record.write(
Expand Down
5 changes: 5 additions & 0 deletions l10n_br_repair/models/repair_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ def _get_amount_lines(self):
lines += [lin for lin in self.mapped("fees_lines")]
return lines

def _get_product_amount_lines(self):
"""Get object lines instaces used to compute fields"""

return self._get_amount_lines()

@api.depends("operations", "fees_lines")
def _compute_amount(self):
return super()._compute_amount()
Expand Down

0 comments on commit c5ed4a7

Please sign in to comment.