product_template.py 1.9 KB

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