diff --git a/addons/sale_expense/models/product_template.py b/addons/sale_expense/models/product_template.py index 686dc7e7be5..54a5058e8d1 100644 --- a/addons/sale_expense/models/product_template.py +++ b/addons/sale_expense/models/product_template.py @@ -39,3 +39,8 @@ class ProductTemplate(models.Model): for product_template in expense_products: if not product_template.visible_expense_policy: product_template.visible_expense_policy = visibility + + @api.depends('can_be_expensed') + def _compute_expense_policy(self): + super()._compute_expense_policy() + self.filtered(lambda t: not t.can_be_expensed).expense_policy = 'no' diff --git a/addons/sale_expense/tests/test_sale_expense.py b/addons/sale_expense/tests/test_sale_expense.py index 4081e7baef6..04b78bb31d5 100644 --- a/addons/sale_expense/tests/test_sale_expense.py +++ b/addons/sale_expense/tests/test_sale_expense.py @@ -2,7 +2,7 @@ from odoo import Command, fields from odoo.addons.hr_expense.tests.common import TestExpenseCommon from odoo.addons.sale.tests.common import TestSaleCommon -from odoo.tests import tagged +from odoo.tests import Form, tagged @tagged('post_install', '-at_install') @@ -149,3 +149,24 @@ class TestSaleExpense(TestExpenseCommon, TestSaleCommon): expense_sheet.action_sheet_move_create() self.assertTrue(self.env['account.move'].search([('expense_sheet_id', '=', expense_sheet.id)], limit=1)) + + def test_analytic_account_expense_policy(self): + with Form(self.product_a.product_tmpl_id) as product_form: + product_form.can_be_expensed = True + product_form.expense_policy = 'cost' + product_form.can_be_expensed = False + + self.product_a.product_tmpl_id = product_form.save() + + so = self.env['sale.order'].create({ + 'partner_id': self.partner_a.id, + 'order_line': [(0, 0, { + 'name': self.product_a.name, + 'product_id': self.product_a.id, + 'product_uom_qty': 2, + 'product_uom': self.product_a.uom_id.id, + 'price_unit': self.product_a.list_price, + })], + }) + so.action_confirm() + self.assertFalse(so.analytic_account_id) diff --git a/addons/sale_timesheet/tests/test_reinvoice.py b/addons/sale_timesheet/tests/test_reinvoice.py index 30449c6fb97..e33fb6b2fa7 100644 --- a/addons/sale_timesheet/tests/test_reinvoice.py +++ b/addons/sale_timesheet/tests/test_reinvoice.py @@ -21,11 +21,13 @@ class TestReInvoice(TestCommonSaleTimesheet): 'service_type': 'timesheet', 'service_tracking': 'task_in_project' } + cls.company_data['product_order_no'].write(service_values) + service_values['expense_policy'] = 'cost' cls.company_data['product_order_cost'].write(service_values) cls.company_data['product_delivery_cost'].write(service_values) + service_values['expense_policy'] = 'sales_price' cls.company_data['product_order_sales_price'].write(service_values) cls.company_data['product_delivery_sales_price'].write(service_values) - cls.company_data['product_order_no'].write(service_values) # create AA, SO and invoices cls.analytic_plan = cls.env['account.analytic.plan'].create({