Debian Codegraph @

addons/sale_expense/models/product_template.py

raw
1 # -*- coding: utf-8 -*-
2 # Part of Odoo. See LICENSE file for full copyright and licensing details.
3
4 from odoo import api, models, fields, _
5
6
7 class ProductTemplate(models.Model):
8 _inherit = 'product.template'
9
10 expense_policy_tooltip = fields.Char(compute='_compute_expense_policy_tooltip')
11
12 @api.depends_context('lang')
13 @api.depends('expense_policy')
14 def _compute_expense_policy_tooltip(self):
15 for product_template in self:
16 if not product_template.can_be_expensed or not product_template.expense_policy:
17 product_template.expense_policy_tooltip = False
18 elif product_template.expense_policy == 'no':
19 product_template.expense_policy_tooltip = _(
20 "Expenses of this category may not be added to a Sales Order."
21 )
22 elif product_template.expense_policy == 'cost':
23 product_template.expense_policy_tooltip = _(
24 "Expenses will be added to the Sales Order at their actual cost when posted."
25 )
26 elif product_template.expense_policy == 'sales_price':
27 product_template.expense_policy_tooltip = _(
28 "Expenses will be added to the Sales Order at their sales price (product price, pricelist, etc.) when posted."
29 )
30
31 @api.depends('can_be_expensed')
32 def _compute_visible_expense_policy(self):
33 expense_products = self.filtered(lambda p: p.can_be_expensed)
34 super(ProductTemplate, self - expense_products)._compute_visible_expense_policy()
35 visibility = self.env.user.has_group('hr_expense.group_hr_expense_user')
36 for product_template in expense_products:
37 if not product_template.visible_expense_policy:
38 product_template.visible_expense_policy = visibility
39
40 @api.depends('can_be_expensed')
41 def _compute_expense_policy(self):
42 super()._compute_expense_policy()
43 self.filtered(lambda t: not t.can_be_expensed).expense_policy = 'no'