| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
from datetime import datetime, timedelta |
| 5 |
from odoo.addons.stock.tests.common import TestStockCommon |
| 6 |
from odoo.tests import Form |
| 7 |
from odoo.exceptions import UserError |
| 8 |
|
| 9 |
|
| 10 |
class TestStockLot(TestStockCommon): |
| 11 |
|
| 12 |
@classmethod |
| 13 |
def setUpClass(cls): |
| 14 |
super().setUpClass() |
| 15 |
|
| 16 |
cls.product_apple = cls.ProductObj.create({ |
| 17 |
'name': 'Apple', |
| 18 |
'is_storable': True, |
| 19 |
'tracking': 'lot', |
| 20 |
'use_expiration_date': True, |
| 21 |
'expiration_time': 10, |
| 22 |
'use_time': 5, |
| 23 |
'removal_time': 8, |
| 24 |
'alert_time': 4, |
| 25 |
}) |
| 26 |
|
| 27 |
lot_form = Form(cls.LotObj) |
| 28 |
lot_form.name = 'good-apple-lot' |
| 29 |
lot_form.product_id = cls.product_apple |
| 30 |
cls.lot_good_apple = lot_form.save() |
| 31 |
|
| 32 |
lot_form = Form(cls.LotObj) |
| 33 |
lot_form.name = 'expired-apple-lot-01' |
| 34 |
lot_form.product_id = cls.product_apple |
| 35 |
cls.lot_expired_apple = lot_form.save() |
| 36 |
lot_form = Form(cls.lot_expired_apple) |
| 37 |
lot_form.expiration_date = datetime.today() - timedelta(days=10) |
| 38 |
cls.lot_expired_apple = lot_form.save() |
| 39 |
|
| 40 |
|
| 41 |
cls.product_apple_pie = cls.ProductObj.create({ |
| 42 |
'name': 'Apple Pie', |
| 43 |
'is_storable': True, |
| 44 |
}) |
| 45 |
cls.bom_apple_pie = cls.env['mrp.bom'].create({ |
| 46 |
'product_id': cls.product_apple_pie.id, |
| 47 |
'product_tmpl_id': cls.product_apple_pie.product_tmpl_id.id, |
| 48 |
'product_uom_id': cls.uom_unit.id, |
| 49 |
'product_qty': 1.0, |
| 50 |
'consumption': 'flexible', |
| 51 |
'type': 'normal', |
| 52 |
'bom_line_ids': [ |
| 53 |
(0, 0, {'product_id': cls.product_apple.id, 'product_qty': 3}), |
| 54 |
]}) |
| 55 |
|
| 56 |
cls.location_stock = cls.env['stock.location'].browse(cls.stock_location) |
| 57 |
|
| 58 |
def test_01_product_produce(self): |
| 59 |
""" Checks user doesn't get a confirmation wizard when they produces with |
| 60 |
no expired components. """ |
| 61 |
|
| 62 |
mo_form = Form(self.env['mrp.production']) |
| 63 |
mo_form.product_id = self.product_apple_pie |
| 64 |
mo_form.bom_id = self.bom_apple_pie |
| 65 |
mo_form.product_qty = 1 |
| 66 |
mo = mo_form.save() |
| 67 |
mo.action_confirm() |
| 68 |
|
| 69 |
mo_form = Form(mo) |
| 70 |
mo_form.qty_producing = 1 |
| 71 |
mo = mo_form.save() |
| 72 |
details_operation_form = Form(mo.move_raw_ids[0], view=self.env.ref('stock.view_stock_move_operations')) |
| 73 |
with details_operation_form.move_line_ids.edit(0) as ml: |
| 74 |
ml.quantity = 3 |
| 75 |
ml.lot_id = self.lot_good_apple |
| 76 |
details_operation_form.save() |
| 77 |
res = mo.button_mark_done() |
| 78 |
|
| 79 |
self.assertEqual(res, True) |
| 80 |
|
| 81 |
def test_02_product_produce_using_expired(self): |
| 82 |
""" Checks user gets a confirmation wizard when they produces with |
| 83 |
expired components. """ |
| 84 |
|
| 85 |
mo_form = Form(self.env['mrp.production']) |
| 86 |
mo_form.product_id = self.product_apple_pie |
| 87 |
mo_form.bom_id = self.bom_apple_pie |
| 88 |
mo_form.product_qty = 1 |
| 89 |
mo = mo_form.save() |
| 90 |
mo.action_confirm() |
| 91 |
|
| 92 |
mo_form = Form(mo) |
| 93 |
mo_form.qty_producing = 1 |
| 94 |
mo = mo_form.save() |
| 95 |
details_operation_form = Form(mo.move_raw_ids[0], view=self.env.ref('stock.view_stock_move_operations')) |
| 96 |
with details_operation_form.move_line_ids.edit(0) as ml: |
| 97 |
ml.quantity = 3 |
| 98 |
ml.lot_id = self.lot_expired_apple |
| 99 |
details_operation_form.save() |
| 100 |
res = mo.button_mark_done() |
| 101 |
|
| 102 |
self.assertNotEqual(res, None) |
| 103 |
self.assertEqual(res['res_model'], 'expiry.picking.confirmation') |