Skip to content

Commit bcb1915

Browse files
committed
[ADD] bookstore: tests on keys automations
task-4715882 closes #741 X-original-commit: e596b00 Signed-off-by: Vallaeys Valentin (vava) <[email protected]>
1 parent d6b55f4 commit bcb1915

File tree

4 files changed

+94
-0
lines changed

4 files changed

+94
-0
lines changed

tests/test_bookstore/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Part of Odoo. See LICENSE file for full copyright and licensing details.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
'name': 'Test Bookstore',
3+
'version': '1.0',
4+
'category': 'Hidden/Tests',
5+
'description': """A module to test code in the bookstore industry.""",
6+
'depends': ['base'],
7+
'license': 'LGPL-3',
8+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Part of Odoo. See LICENSE file for full copyright and licensing details.
2+
3+
from . import test_action_server
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# Part of Odoo. See LICENSE file for full copyright and licensing details.
2+
3+
from odoo import fields
4+
from odoo.tests.common import TransactionCase
5+
from odoo.tests import tagged, Form
6+
7+
8+
@tagged('post_install', '-at_install')
9+
class BookstoreAutomationsTestCase(TransactionCase):
10+
@classmethod
11+
def setUpClass(cls):
12+
super().setUpClass()
13+
cls.product = cls.env['product.template'].create({
14+
'name': 'Test Book',
15+
'list_price': 20.0,
16+
})
17+
18+
def test_update_inventory_description_automation(self):
19+
# Empty description case
20+
self.assertEqual(self.product.description_pickingin, '[20.0]')
21+
self.product.list_price = 24.99
22+
self.assertEqual(self.product.description_pickingin, '[24.99]')
23+
24+
# Description should be overridden correctly
25+
self.product.description_pickingin = '[24.99] Updated description'
26+
self.product.list_price = 30.0
27+
self.assertEqual(self.product.description_pickingin, '[30.0] Updated description')
28+
29+
# Description should be overridden
30+
self.product.description_pickingin = 'Updated description'
31+
self.product.list_price = 32.99
32+
self.assertEqual(self.product.description_pickingin, '[32.99]')
33+
34+
# Test the form view
35+
with Form(self.product) as product_form:
36+
product_form.list_price = 35.0
37+
self.assertEqual(self.product.description_pickingin, '[35.0]')
38+
39+
def test_update_supplierinfo_on_incoming_picking(self):
40+
vendor, vendor2 = self.env['res.partner'].create([{'name': 'Test Vendor'}, {'name': 'Test Vendor 2'}])
41+
product = self.env['product.product'].create({
42+
'name': 'Test Product',
43+
'list_price': 10.0,
44+
})
45+
self.env['product.supplierinfo'].create({
46+
'partner_id': vendor.id,
47+
'product_id': product.id,
48+
'price': 5.0,
49+
'delay': 0,
50+
'min_qty': 1,
51+
})
52+
53+
self.assertEqual(product.seller_ids.partner_id, vendor,
54+
"The product should have a supplierinfo for the vendor")
55+
56+
# Create an incoming picking with another vendor
57+
picking = self.env['stock.picking'].create({
58+
'partner_id': vendor2.id,
59+
'picking_type_id': self.env.ref('stock.picking_type_in').id,
60+
'location_id': self.env.ref('stock.stock_location_suppliers').id,
61+
'location_dest_id': self.env.ref('stock.stock_location_stock').id,
62+
'move_ids_without_package': [(0, 0, {
63+
'name': product.name,
64+
'product_id': product.id,
65+
'product_uom_qty': 1,
66+
})],
67+
})
68+
69+
picking.button_validate()
70+
self.assertEqual(product.seller_ids[-1].partner_id, vendor2,
71+
"Vendor should be updated to the new supplierinfo from the incoming picking")
72+
self.assertEqual(product.seller_ids[-1].date_start, fields.Date.today(),
73+
"The new supplierinfo should have today's date as start date")
74+
self.assertEqual(product.seller_ids[-2].partner_id, vendor,
75+
"The previous supplierinfo should still exist")
76+
self.assertEqual(product.seller_ids[-2].date_end, fields.Date.today(),
77+
"The previous supplierinfo should be closed with today's date")
78+
79+
self.assertTrue(picking.purchase_id, "A purchase order linked to the picking should be created")
80+
self.assertEqual(picking.purchase_id.partner_id, vendor2, "The purchase order should be for the correct vendor")
81+
self.assertEqual(picking.purchase_id.state, 'purchase', "The purchase order should be confirmed")
82+

0 commit comments

Comments
 (0)