Purpose: Sometimes, taxes are distinct on parts of the expense (for example alcohol and food). Therefore the expense should be split in two. In order to split the expense, we added an wizard. When creating a new expense from the split, we also copy the attachments. 'hr.expense.split' has to have the similar logic and dependencies between the fields as 'hr.expense' does. For example, in case we change the product_id to the product that has cost defined on it, it should have the same behavior as expense has. In particular, the 'total_price' will be set and the user should not be able to modify the amount. Similarly, if we change the product_id to the one that has no tax defined on it, then split tax_ids should be cleared out and be set to readonly. Similar logic goes to sale_order_id (Customer to Reinvoice'), we should not be able to set it, in case the product can not be re-invoiced. All of the above constraints leads to the amount of similar code to to the 'hr.expense.split' side. But it could not have been avoided, if we want the smooth flow. task - 2831024 closes odoo/odoo#90770 Signed-off-by: Kevin Baptiste <kba@odoo.com>
35 lines
1.4 KiB
Python
35 lines
1.4 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from odoo import fields, models, api
|
|
|
|
|
|
class HrExpenseSplit(models.TransientModel):
|
|
_inherit = "hr.expense.split"
|
|
|
|
def default_get(self, fields):
|
|
result = super(HrExpenseSplit, self).default_get(fields)
|
|
if 'expense_id' in result:
|
|
expense = self.env['hr.expense'].browse(result['expense_id'])
|
|
result['sale_order_id'] = expense.sale_order_id
|
|
return result
|
|
|
|
sale_order_id = fields.Many2one('sale.order', string="Customer to Reinvoice", compute='_compute_sale_order_id', readonly=False, store=True, domain="[('state', '=', 'sale'), ('company_id', '=', company_id)]")
|
|
can_be_reinvoiced = fields.Boolean("Can be reinvoiced", compute='_compute_can_be_reinvoiced')
|
|
|
|
def _get_values(self):
|
|
self.ensure_one()
|
|
vals = super(HrExpenseSplit, self)._get_values()
|
|
vals['sale_order_id'] = self.sale_order_id.id
|
|
return vals
|
|
|
|
@api.depends('product_id')
|
|
def _compute_can_be_reinvoiced(self):
|
|
for split in self:
|
|
split.can_be_reinvoiced = split.product_id.expense_policy in ['sales_price', 'cost']
|
|
|
|
@api.depends('can_be_reinvoiced')
|
|
def _compute_sale_order_id(self):
|
|
for split in self:
|
|
split.sale_order_id = split.sale_order_id if split.can_be_reinvoiced else False
|