Impacted modules: sale, hr_expense, sale_stock and sale_expense. The reinvoice policy has nothing to do with the fact a product can be expensed or not by employee, because of the vendor bills use case. You can only choose reinvoice policy of your product when hr_expense is installed, which is not very intuitive for users. So this commit makes reinvoice policy field always visible when sale is installed. 'can_be_expensed' field determines if the product can be used in HR expense. However, since reinvoice policy does not make much sense for stockable products, we hide this option and reset it to 'no' when sale_stock module is installed, as we don't handle stock for those expensed products (when confirming expense, the product is already delivered).
24 lines
842 B
Python
24 lines
842 B
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from odoo import api, fields, models
|
|
|
|
|
|
class ProductTemplate(models.Model):
|
|
_inherit = "product.template"
|
|
|
|
can_be_expensed = fields.Boolean(help="Specify whether the product can be selected in an HR expense.", string="Can be Expensed")
|
|
|
|
@api.model
|
|
def create(self, vals):
|
|
# When creating an expense product on the fly, you don't expect to
|
|
# have taxes on it
|
|
if vals.get('can_be_expensed', False):
|
|
vals.update({'supplier_taxes_id': False})
|
|
return super(ProductTemplate, self).create(vals)
|
|
|
|
@api.onchange('type')
|
|
def _onchange_type_for_expense(self):
|
|
if self.type not in ['consu', 'service']: # stockable can not be expensed.
|
|
self.can_be_expensed = False
|