| 1 |
|
| 2 |
|
| 3 |
from odoo.fields import Command |
| 4 |
from odoo.tests import HttpCase, tagged |
| 5 |
|
| 6 |
from odoo.addons.account.tests.common import AccountTestInvoicingCommon |
| 7 |
from odoo.addons.product.tests.test_product_attribute_value_config import ( |
| 8 |
TestProductAttributeValueCommon, |
| 9 |
) |
| 10 |
|
| 11 |
|
| 12 |
@tagged('post_install', '-at_install') |
| 13 |
class TestWebsiteSaleMrpAvailability(HttpCase, AccountTestInvoicingCommon, TestProductAttributeValueCommon): |
| 14 |
|
| 15 |
@classmethod |
| 16 |
def setUpClass(cls): |
| 17 |
super().setUpClass() |
| 18 |
|
| 19 |
|
| 20 |
cls.company = cls.env['res.company'].create({'name': 'Kit Company'}) |
| 21 |
cls.env = cls.env['base'].with_company(cls.company).env |
| 22 |
cls.env.user.company_id = cls.company |
| 23 |
cls.website = cls.env.ref('website.default_website') |
| 24 |
cls.website.company_id = cls.env.company |
| 25 |
cls.warehouse = cls.env['stock.warehouse'].search([('company_id', '=', cls.company.id)], limit=1) |
| 26 |
|
| 27 |
|
| 28 |
cls.super_kit_product, cls.kit_product, cls.component_A, cls.component_B = cls.env['product.product'].create([ |
| 29 |
{ |
| 30 |
'name': product_name, |
| 31 |
'allow_out_of_stock_order': False, |
| 32 |
'type': 'consu', |
| 33 |
'is_storable': True, |
| 34 |
'website_published': True, |
| 35 |
'show_availability': True, |
| 36 |
'available_threshold': 100, |
| 37 |
} for product_name in ("Super Kit Product", "Kit Product", "Component A", "Component B") |
| 38 |
]) |
| 39 |
|
| 40 |
cls.consumable_component = cls.env['product.product'].create({ |
| 41 |
'name': "Consumable Component", |
| 42 |
'allow_out_of_stock_order': False, |
| 43 |
'type': 'consu', |
| 44 |
'is_storable': False, |
| 45 |
'website_published': True, |
| 46 |
'show_availability': True, |
| 47 |
'available_threshold': 100, |
| 48 |
}) |
| 49 |
|
| 50 |
cls.super_kit_bom, cls.kit_bom = cls.env['mrp.bom'].create([ |
| 51 |
{ |
| 52 |
'product_tmpl_id': cls.super_kit_product.product_tmpl_id.id, |
| 53 |
'type': 'phantom', |
| 54 |
'product_qty': 2, |
| 55 |
'bom_line_ids': [ |
| 56 |
Command.create({'product_id': cls.component_A.id, 'product_qty': 8}), |
| 57 |
Command.create({'product_id': cls.kit_product.id, 'product_qty': 2}), |
| 58 |
Command.create({'product_id': cls.consumable_component.id, 'product_qty': 1}), |
| 59 |
], |
| 60 |
}, |
| 61 |
{ |
| 62 |
'product_tmpl_id': cls.kit_product.product_tmpl_id.id, |
| 63 |
'type': 'phantom', |
| 64 |
'product_qty': 1, |
| 65 |
'bom_line_ids': [ |
| 66 |
Command.create({'product_id': cls.component_A.id, 'product_qty': 1}), |
| 67 |
Command.create({'product_id': cls.component_B.id, 'product_qty': 5}), |
| 68 |
Command.create({'product_id': cls.consumable_component.id, 'product_qty': 1}), |
| 69 |
], |
| 70 |
}, |
| 71 |
]) |
| 72 |
|
| 73 |
|
| 74 |
cls.env['stock.quant']._update_available_quantity(cls.component_A, cls.warehouse.lot_stock_id, 100) |
| 75 |
cls.env['stock.quant']._update_available_quantity(cls.component_B, cls.warehouse.lot_stock_id, 100) |
| 76 |
|
| 77 |
def test_website_sale_availability_kit(self): |
| 78 |
""" |
| 79 |
Check that the website availability of products is influenced by kits present in the cart. |
| 80 |
""" |
| 81 |
if self.env['ir.module.module']._get('website_sale_collect').state == 'installed': |
| 82 |
|
| 83 |
self.website.in_store_dm_id.is_published = False |
| 84 |
self.start_tour("/shop", 'test_website_sale_availability_kit', login="") |