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,10 +1,8 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo.fields import Command
from odoo.tests import TransactionCase
from odoo.addons.account.tests.common import AccountTestInvoicingCommon
from odoo.addons.account.tests.common import AccountTestInvoicingCommon, TestTaxCommon
from odoo.addons.product.tests.common import ProductCommon
from odoo.addons.sales_team.tests.common import SalesTeamCommon
@ -18,223 +16,239 @@ class SaleCommon(
def setUpClass(cls):
super().setUpClass()
cls.env.company.country_id = cls.env.ref('base.us')
cls.env.company.country_id = cls.quick_ref('base.us')
# Not defined in product common because only used in sale
cls.group_discount_per_so_line = cls.env.ref('product.group_discount_per_so_line')
cls.group_discount_per_so_line = cls.quick_ref('sale.group_discount_per_so_line')
cls.empty_order = cls.env['sale.order'].create({
'partner_id': cls.partner.id,
(cls.product + cls.service_product).write({
'taxes_id': [Command.clear()],
})
cls.sale_order = cls.env['sale.order'].create({
'partner_id': cls.partner.id,
cls._enable_pricelists()
cls.empty_order, cls.sale_order = cls.env['sale.order'].create([
{
'partner_id': cls.partner.id,
}, {
'partner_id': cls.partner.id,
'order_line': [
Command.create({
'product_id': cls.product.id,
'product_uom_qty': 5.0,
}),
Command.create({
'product_id': cls.service_product.id,
'product_uom_qty': 12.5,
})
]
},
])
@classmethod
def _enable_discounts(cls):
cls.env.user.group_ids += cls.group_discount_per_so_line
def _create_so(self, **values):
default_values = {
'partner_id': self.partner.id,
'order_line': [
Command.create({
'product_id': cls.consumable_product.id,
'product_uom_qty': 5.0,
'product_id': self.product.id,
}),
Command.create({
'product_id': cls.service_product.id,
'product_uom_qty': 12.5,
})
]
})
],
**values
}
return self.env['sale.order'].create(default_values)
class TestSaleCommon(AccountTestInvoicingCommon):
@classmethod
def _enable_pricelists(cls):
cls.env.user.groups_id += cls.env.ref('product.group_product_pricelist')
class TestSaleCommonBase(TransactionCase):
''' Setup with sale test configuration. '''
@classmethod
def setup_sale_configuration_for_company(cls, company):
Users = cls.env['res.users'].with_context(no_reset_password=True)
company_data = {
# Sales Team
'default_sale_team': cls.env['crm.team'].with_context(tracking_disable=True).create({
'name': 'Test Channel',
'company_id': company.id,
}),
def collect_company_accounting_data(cls, company):
company_data = super().collect_company_accounting_data(company)
company_data.update({
# Users
'default_user_salesman': Users.create({
'default_user_salesman': cls.env['res.users'].create({
'name': 'default_user_salesman',
'login': 'default_user_salesman.comp%s' % company.id,
'email': 'default_user_salesman@example.com',
'signature': '--\nMark',
'notification_type': 'email',
'groups_id': [(6, 0, cls.env.ref('sales_team.group_sale_salesman').ids)],
'company_ids': [(6, 0, company.ids)],
'company_id': company.id,
}),
'default_user_portal': Users.create({
'name': 'default_user_portal',
'login': 'default_user_portal.comp%s' % company.id,
'email': 'default_user_portal@gladys.portal',
'groups_id': [(6, 0, [cls.env.ref('base.group_portal').id])],
'company_ids': [(6, 0, company.ids)],
'company_id': company.id,
}),
'default_user_employee': Users.create({
'name': 'default_user_employee',
'login': 'default_user_employee.comp%s' % company.id,
'email': 'default_user_employee@example.com',
'groups_id': [(6, 0, [cls.env.ref('base.group_user').id])],
'group_ids': [(6, 0, cls.quick_ref('sales_team.group_sale_salesman').ids)],
'company_ids': [(6, 0, company.ids)],
'company_id': company.id,
}),
# Pricelist
'default_pricelist': cls.env['product.pricelist'].with_company(company).create({
'name': 'default_pricelist',
'currency_id': company.currency_id.id,
}),
# Product category
'product_category': cls.env['product.category'].with_company(company).create({
'name': 'Test category',
}),
}
company_data.update({
# Products
'product_service_delivery': cls.env['product.product'].with_company(company).create({
'name': 'product_service_delivery',
'categ_id': company_data['product_category'].id,
'categ_id': cls.product_category.id,
'standard_price': 200.0,
'list_price': 180.0,
'type': 'service',
'uom_id': cls.env.ref('uom.product_uom_unit').id,
'uom_po_id': cls.env.ref('uom.product_uom_unit').id,
'uom_id': cls.uom_unit.id,
'default_code': 'SERV_DEL',
'invoice_policy': 'delivery',
'taxes_id': [(6, 0, [])],
'supplier_taxes_id': [(6, 0, [])],
'company_id': company.id,
}),
'product_service_order': cls.env['product.product'].with_company(company).create({
'name': 'product_service_order',
'categ_id': company_data['product_category'].id,
'categ_id': cls.product_category.id,
'standard_price': 40.0,
'list_price': 90.0,
'type': 'service',
'uom_id': cls.env.ref('uom.product_uom_hour').id,
'uom_po_id': cls.env.ref('uom.product_uom_hour').id,
'uom_id': cls.uom_hour.id,
'description': 'Example of product to invoice on order',
'default_code': 'PRE-PAID',
'invoice_policy': 'order',
'taxes_id': [(6, 0, [])],
'supplier_taxes_id': [(6, 0, [])],
'company_id': company.id,
}),
'product_order_cost': cls.env['product.product'].with_company(company).create({
'name': 'product_order_cost',
'categ_id': company_data['product_category'].id,
'categ_id': cls.product_category.id,
'standard_price': 235.0,
'list_price': 280.0,
'type': 'consu',
'weight': 0.01,
'uom_id': cls.env.ref('uom.product_uom_unit').id,
'uom_po_id': cls.env.ref('uom.product_uom_unit').id,
'uom_id': cls.uom_unit.id,
'default_code': 'FURN_9999',
'invoice_policy': 'order',
'expense_policy': 'cost',
'taxes_id': [(6, 0, [])],
'supplier_taxes_id': [(6, 0, [])],
'company_id': company.id,
}),
'product_delivery_cost': cls.env['product.product'].with_company(company).create({
'name': 'product_delivery_cost',
'categ_id': company_data['product_category'].id,
'categ_id': cls.product_category.id,
'standard_price': 55.0,
'list_price': 70.0,
'type': 'consu',
'weight': 0.01,
'uom_id': cls.env.ref('uom.product_uom_unit').id,
'uom_po_id': cls.env.ref('uom.product_uom_unit').id,
'uom_id': cls.uom_unit.id,
'default_code': 'FURN_7777',
'invoice_policy': 'delivery',
'expense_policy': 'cost',
'taxes_id': [(6, 0, [])],
'supplier_taxes_id': [(6, 0, [])],
'company_id': company.id,
}),
'product_order_sales_price': cls.env['product.product'].with_company(company).create({
'name': 'product_order_sales_price',
'categ_id': company_data['product_category'].id,
'categ_id': cls.product_category.id,
'standard_price': 235.0,
'list_price': 280.0,
'type': 'consu',
'weight': 0.01,
'uom_id': cls.env.ref('uom.product_uom_unit').id,
'uom_po_id': cls.env.ref('uom.product_uom_unit').id,
'uom_id': cls.uom_unit.id,
'default_code': 'FURN_9999',
'invoice_policy': 'order',
'expense_policy': 'sales_price',
'taxes_id': [(6, 0, [])],
'supplier_taxes_id': [(6, 0, [])],
'company_id': company.id,
}),
'product_delivery_sales_price': cls.env['product.product'].with_company(company).create({
'name': 'product_delivery_sales_price',
'categ_id': company_data['product_category'].id,
'categ_id': cls.product_category.id,
'standard_price': 55.0,
'list_price': 70.0,
'type': 'consu',
'weight': 0.01,
'uom_id': cls.env.ref('uom.product_uom_unit').id,
'uom_po_id': cls.env.ref('uom.product_uom_unit').id,
'uom_id': cls.uom_unit.id,
'default_code': 'FURN_7777',
'invoice_policy': 'delivery',
'expense_policy': 'sales_price',
'taxes_id': [(6, 0, [])],
'supplier_taxes_id': [(6, 0, [])],
'company_id': company.id,
}),
'product_order_no': cls.env['product.product'].with_company(company).create({
'name': 'product_order_no',
'categ_id': company_data['product_category'].id,
'categ_id': cls.product_category.id,
'standard_price': 235.0,
'list_price': 280.0,
'type': 'consu',
'weight': 0.01,
'uom_id': cls.env.ref('uom.product_uom_unit').id,
'uom_po_id': cls.env.ref('uom.product_uom_unit').id,
'uom_id': cls.uom_unit.id,
'default_code': 'FURN_9999',
'invoice_policy': 'order',
'expense_policy': 'no',
'taxes_id': [(6, 0, [])],
'supplier_taxes_id': [(6, 0, [])],
'company_id': company.id,
}),
'product_delivery_no': cls.env['product.product'].with_company(company).create({
'name': 'product_delivery_no',
'categ_id': company_data['product_category'].id,
'categ_id': cls.product_category.id,
'standard_price': 55.0,
'list_price': 70.0,
'type': 'consu',
'weight': 0.01,
'uom_id': cls.env.ref('uom.product_uom_unit').id,
'uom_po_id': cls.env.ref('uom.product_uom_unit').id,
'uom_id': cls.uom_unit.id,
'default_code': 'FURN_7777',
'invoice_policy': 'delivery',
'expense_policy': 'no',
'taxes_id': [(6, 0, [])],
'supplier_taxes_id': [(6, 0, [])],
'company_id': company.id,
}),
})
return company_data
@classmethod
def get_default_groups(cls):
groups = super().get_default_groups()
return groups | cls.quick_ref('sales_team.group_sale_manager')
class TestSaleCommon(AccountTestInvoicingCommon, TestSaleCommonBase):
''' Setup to be used post-install with sale and accounting test configuration.'''
class TestTaxCommonSale(TestSaleCommon, TestTaxCommon):
@classmethod
def setup_company_data(cls, company_name, chart_template=None, **kwargs):
company_data = super().setup_company_data(company_name, chart_template=chart_template, **kwargs)
company_data.update(cls.setup_sale_configuration_for_company(company_data['company']))
company_data['product_category'].write({
'property_account_income_categ_id': company_data['default_account_revenue'].id,
'property_account_expense_categ_id': company_data['default_account_expense'].id,
def setUpClass(cls):
super().setUpClass()
cls.foreign_currency_pricelist = cls.env['product.pricelist'].create({
'name': "TestTaxCommonSale",
'currency_id': cls.foreign_currency.id,
'company_id': cls.env.company.id,
})
return company_data
def convert_document_to_sale_order(self, document):
order_date = '2020-01-01'
currency = document['currency']
self._ensure_rate(currency, order_date, document['rate'])
self.foreign_currency_pricelist.currency_id = currency
return self.env['sale.order'].create({
'date_order': order_date,
'currency_id': currency.id,
'partner_id': self.partner_a.id,
'pricelist_id': self.foreign_currency_pricelist.id,
'order_line': [
Command.create({
'name': str(i),
'product_id': (base_line['product_id'] or self.product_a).id,
'price_unit': base_line['price_unit'],
'discount': base_line['discount'],
'product_uom_qty': base_line['quantity'],
'tax_ids': [Command.set(base_line['tax_ids'].ids)],
})
for i, base_line in enumerate(document['lines'])
],
})
def assert_sale_order_tax_totals_summary(self, sale_order, expected_values, soft_checking=False):
self._assert_tax_totals_summary(sale_order.tax_totals, expected_values, soft_checking=soft_checking)
cash_rounding_base_amount_currency = sale_order.tax_totals.get('cash_rounding_base_amount_currency', 0.0)
expected_amounts = {}
if 'base_amount_currency' in expected_values:
expected_amounts['amount_untaxed'] = expected_values['base_amount_currency'] + cash_rounding_base_amount_currency
if 'tax_amount_currency' in expected_values:
expected_amounts['amount_tax'] = expected_values['tax_amount_currency']
if 'total_amount_currency' in expected_values:
expected_amounts['amount_total'] = expected_values['total_amount_currency']
self.assertRecordValues(sale_order, [expected_amounts])