19.0 vanilla

This commit is contained in:
Ernad Husremovic 2026-03-09 09:32:12 +01:00
parent 79f83631d5
commit 73afc09215
6267 changed files with 1534193 additions and 1130106 deletions

View file

@ -1,9 +1,11 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo.addons.hr_expense.tests.common import TestExpenseCommon
from odoo.fields import Command
from odoo.tests import tagged
from odoo.addons.hr_expense.tests.common import TestExpenseCommon
@tagged('-at_install', 'post_install')
class TestExpenseMargin(TestExpenseCommon):
@ -11,96 +13,73 @@ class TestExpenseMargin(TestExpenseCommon):
# re-invoiceable products
product_with_cost = self.product_a
product_with_cost.write({'standard_price': 1000, 'expense_policy': 'sales_price'})
product_with_no_cost = self.product_b
product_with_no_cost.write({'standard_price': 0, 'expense_policy': 'sales_price'})
product_with_no_cost = self.product_c
product_with_no_cost.write({'expense_policy': 'sales_price'})
# create SO line and confirm SO (with only one line)
sale_order = self.env['sale.order'].with_context(mail_notrack=True, mail_create_nolog=True).create({
sale_order = self.env['sale.order'].with_context(
mail_notrack=True,
mail_create_nolog=True,
).sudo().create({
'partner_id': self.partner_a.id,
'partner_invoice_id': self.partner_a.id,
'partner_shipping_id': self.partner_a.id,
'order_line': [(0, 0, {
'order_line': [Command.create({
'name': product_with_cost.name,
'product_id': product_with_cost.id,
'product_uom_qty': 2.0,
'price_unit': 13.0,
})],
})
sale_order.action_confirm()
expense_sheet = self.env['hr.expense.sheet'].create({
'name': 'First Expense for employee',
'employee_id': self.expense_employee.id,
'journal_id': self.company_data['default_journal_purchase'].id,
'accounting_date': '2020-10-12',
'expense_line_ids': [
expense = self.create_expenses([
{
# expense with zero cost product, with 15% tax
(0, 0, {
'name': 'expense_1',
'date': '2020-10-07',
'product_id': product_with_no_cost.id,
'unit_amount': product_with_no_cost.standard_price,
'total_amount': 100,
'tax_ids': [(6, 0, self.company_data['default_tax_purchase'].ids)],
'employee_id': self.expense_employee.id,
'sale_order_id': sale_order.id,
}),
'name': 'expense_1',
'date': '2020-10-07',
'product_id': product_with_no_cost.id,
'total_amount_currency': 100,
'tax_ids': [Command.set(self.company_data['default_tax_purchase'].ids)],
'sale_order_id': sale_order.id,
},
{
# expense with zero cost product, with no tax
(0, 0, {
'name': 'expense_2',
'date': '2020-10-07',
'product_id': product_with_no_cost.id,
'unit_amount': product_with_no_cost.standard_price,
'total_amount': 100,
'tax_ids': False,
'employee_id': self.expense_employee.id,
'sale_order_id': sale_order.id
}),
'name': 'expense_2',
'date': '2020-10-07',
'product_id': product_with_no_cost.id,
'total_amount_currency': 100,
'tax_ids': False,
'sale_order_id': sale_order.id
},
{
# expense with product with cost (1000), with 15% tax
(0, 0, {
'name': 'expense_3',
'date': '2020-10-07',
'product_id': product_with_cost.id,
'quantity': 3,
'unit_amount': product_with_cost.standard_price,
'tax_ids': [(6, 0, self.company_data['default_tax_purchase'].ids)],
'employee_id': self.expense_employee.id,
'sale_order_id': sale_order.id
}),
'name': 'expense_3',
'date': '2020-10-07',
'product_id': product_with_cost.id,
'quantity': 3,
'tax_ids': [Command.set(self.company_data['default_tax_purchase'].ids)],
'sale_order_id': sale_order.id
},
{
# expense with product with cost (1000), with no tax
(0, 0, {
'name': 'expense_4',
'date': '2020-10-07',
'product_id': product_with_cost.id,
'quantity': 5,
'unit_amount': product_with_cost.standard_price,
'tax_ids': False,
'employee_id': self.expense_employee.id,
'sale_order_id': sale_order.id
}),
],
})
'name': 'expense_4',
'date': '2020-10-07',
'product_id': product_with_cost.id,
'quantity': 5,
'tax_ids': False,
'sale_order_id': sale_order.id
},
]).sorted('name')
expense_sheet.approve_expense_sheets()
expense_sheet.action_sheet_move_create()
expense.action_submit()
expense._do_approve() # Skip duplicate wizard
self.post_expenses_with_wizard(expense)
self.assertRecordValues(sale_order.order_line[1:], [
# Expense lines:
{
'purchase_price': 86.96,
'is_expense': True,
},
{
'purchase_price': 100.0,
'is_expense': True,
},
{
'purchase_price': 869.57,
'is_expense': True,
},
{
'purchase_price': 1000.0,
'is_expense': True,
},
])
self.assertAlmostEqual(sale_order.order_line[0].purchase_price, 1000.0)
self.assertFalse(sale_order.order_line[0].is_expense)
# Expense Lines
for line, expected_purchase_price in zip(sale_order.order_line[1:], [86.96, 100.0, 869.5666667, 1000.0]):
self.assertAlmostEqual(line.purchase_price, expected_purchase_price)
self.assertTrue(line.is_expense)