forked from OCA/contract
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontract_line.py
55 lines (50 loc) · 1.86 KB
/
contract_line.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# Copyright 2016 Tecnativa - Pedro M. Baeza
# Copyright 2018 Tecnativa - Carlos Dauden
# Copyright 2018 ACSONE SA/NV
# Copyright 2024 Tecnativa - Carolina Fernandez
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import models
from odoo.tools import float_is_zero
from odoo.tools.safe_eval import safe_eval
class AccountAnalyticInvoiceLine(models.Model):
_inherit = "contract.line"
def _get_quantity_to_invoice(
self, period_first_date, period_last_date, invoice_date
):
quantity = super()._get_quantity_to_invoice(
period_first_date, period_last_date, invoice_date
)
if not period_first_date or not period_last_date or not invoice_date:
return quantity
if self.qty_type == "variable":
eval_context = {
"env": self.env,
"context": self.env.context,
"user": self.env.user,
"line": self,
"quantity": quantity,
"period_first_date": period_first_date,
"period_last_date": period_last_date,
"invoice_date": invoice_date,
"contract": self.contract_id,
}
safe_eval(
str(self.qty_formula_id.code).strip(),
eval_context,
mode="exec",
nocopy=True,
) # nocopy for returning result
quantity = eval_context.get("result", 0)
return quantity
def _prepare_invoice_line(self):
vals = super()._prepare_invoice_line()
if (
"quantity" in vals
and self.contract_id.skip_zero_qty
and float_is_zero(
vals["quantity"],
self.env["decimal.precision"].precision_get("Product Unit of Measure"),
)
):
vals = {}
return vals