-
-
Notifications
You must be signed in to change notification settings - Fork 982
/
product_template.py
54 lines (46 loc) · 1.98 KB
/
product_template.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
# Copyright 2017 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import api, fields, models
class ProductTemplate(models.Model):
_inherit = "product.template"
default_invoice_policy = fields.Selection(
[("order", "Ordered quantities"), ("delivery", "Delivered quantities")],
string="Default Invoicing Policy",
help="Ordered Quantity: Invoice based on the quantity the customer "
"ordered.\n"
"Delivered Quantity: Invoiced based on the quantity the vendor "
"delivered (time or deliveries).",
default=lambda self: self.env["ir.default"].get(
"res.config.settings", "default_invoice_policy"
),
)
invoice_policy = fields.Selection(
compute="_compute_invoice_policy",
store=False,
readonly=True,
search="_search_invoice_policy",
inverse="_inverse_invoice_policy",
precompute=False,
)
def _inverse_invoice_policy(self):
for template in self.filtered("invoice_policy"):
template.default_invoice_policy = template.invoice_policy
@api.depends("detailed_type", "default_invoice_policy")
@api.depends_context("invoice_policy")
def _compute_invoice_policy(self):
"""
Apply the invoice_policy given by context (if exist) otherwise use the
default invoice policy given by the field with this same name.
If the product is type = 'service', we don't have to apply the invoice
policy given by the context.
:return:
"""
invoice_policy = self.env.context.get("invoice_policy")
for tmpl in self:
if tmpl.type != "service" and invoice_policy:
tmpl.invoice_policy = invoice_policy
else:
tmpl.invoice_policy = tmpl.default_invoice_policy
@api.model
def _search_invoice_policy(self, operator, value):
return [("default_invoice_policy", operator, value)]