def test_edit_removal_date_in_inventory_mode(self): """ Try to edit removal_date with the inventory mode. """ user_group_stock_manager = self.env.ref('stock.group_stock_manager') self.demo_user = mail_new_test_user( self.env, name='Demo user', login='******', email='*****@*****.**', groups='stock.group_stock_manager', ) lot_form = Form(self.LotObj) lot_form.name = 'LOT001' lot_form.product_id = self.apple_product lot_form.company_id = self.env.company apple_lot = lot_form.save() quant = self.StockQuantObj.with_context(inventory_mode=True).create({ 'product_id': self.apple_product.id, 'location_id': self.stock_location, 'quantity': 10, 'lot_id': apple_lot.id, }) # Try to write on quant with inventory mode new_date = datetime.today() + timedelta(days=15) quant.with_user(self.demo_user).with_context( inventory_mode=True).write({'removal_date': new_date}) self.assertEqual(quant.removal_date, new_date)
def test_orderpoint_2(self): """As a user of Company A, check it is not possible to change the company on an existing orderpoint to Company B. """ product = self.env['product.product'].create({ 'type': 'product', 'name': 'shared product', }) orderpoint = Form(self.env['stock.warehouse.orderpoint'].with_user( self.user_a)) orderpoint.company_id = self.company_a orderpoint.warehouse_id = self.warehouse_a orderpoint.location_id = self.stock_location_a orderpoint.product_id = product orderpoint = orderpoint.save() self.assertEqual(orderpoint.company_id, self.company_a) with self.assertRaises(UserError): orderpoint.company_id = self.company_b.id
def test_product_1(self): """ As an user of Company A, checks we can or cannot create new product depending of its `company_id`.""" # Creates a new product with no company_id and set a responsible. # The product must be created as there is no company on the product. product_form = Form(self.env['product.template'].with_user( self.user_a)) product_form.name = 'Paramite Pie' product_form.responsible_id = self.user_b product = product_form.save() self.assertEqual(product.company_id.id, False) self.assertEqual(product.responsible_id.id, self.user_b.id) # Creates a new product belong to Company A and set a responsible belong # to Company B. The product mustn't be created as the product and the # user don't belong of the same company. self.user_b.company_ids = [(6, 0, [self.company_b.id])] product_form = Form(self.env['product.template'].with_user( self.user_a)) product_form.name = 'Meech Munchy' product_form.company_id = self.company_a product_form.responsible_id = self.user_b with self.assertRaises(UserError): # Raises an UserError for company incompatibility. product = product_form.save() # Creates a new product belong to Company A and set a responsible belong # to Company A & B (default B). The product must be created as the user # belongs to product's company. self.user_b.company_ids = [(6, 0, [self.company_a.id, self.company_b.id])] product_form = Form(self.env['product.template'].with_user( self.user_a)) product_form.name = 'Scrab Cake' product_form.company_id = self.company_a product_form.responsible_id = self.user_b product = product_form.save() self.assertEqual(product.company_id.id, self.company_a.id) self.assertEqual(product.responsible_id.id, self.user_b.id)
def test_03_onchange_expiration_date(self): """ Updates the `expiration_date` of the lot production and checks other date fields are updated as well. """ # Keeps track of the current datetime and set a delta for the compares. today_date = datetime.today() time_gap = timedelta(seconds=10) # Creates a new lot number and saves it... lot_form = Form(self.LotObj) lot_form.name = 'Apple Box #1' lot_form.product_id = self.apple_product lot_form.company_id = self.env.company apple_lot = lot_form.save() # ...then checks date fields have the expected values. self.assertAlmostEqual( today_date + timedelta(days=self.apple_product.expiration_time), apple_lot.expiration_date, delta=time_gap) self.assertAlmostEqual(today_date + timedelta(days=self.apple_product.use_time), apple_lot.use_date, delta=time_gap) self.assertAlmostEqual(today_date + timedelta(days=self.apple_product.removal_time), apple_lot.removal_date, delta=time_gap) self.assertAlmostEqual(today_date + timedelta(days=self.apple_product.alert_time), apple_lot.alert_date, delta=time_gap) difference = timedelta(days=20) new_date = apple_lot.expiration_date + difference old_use_date = apple_lot.use_date old_removal_date = apple_lot.removal_date old_alert_date = apple_lot.alert_date # Modifies the lot `expiration_date`... lot_form = Form(apple_lot) lot_form.expiration_date = new_date apple_lot = lot_form.save() # ...then checks all other date fields were correclty updated. self.assertAlmostEqual(apple_lot.use_date, old_use_date + difference, delta=time_gap) self.assertAlmostEqual(apple_lot.removal_date, old_removal_date + difference, delta=time_gap) self.assertAlmostEqual(apple_lot.alert_date, old_alert_date + difference, delta=time_gap)
def test_putaway_1(self): """As a user of Company A, create a putaway rule with locations of Company A and set the company to Company B before saving. Check it is not possible. """ stock_location_a_1 = self.env['stock.location'].with_user( self.user_a).create({ 'location_id': self.stock_location_a.id, 'usage': 'internal', 'name': 'A_1', }) putaway_form = Form(self.env['stock.putaway.rule']) putaway_form.location_in_id = self.stock_location_a putaway_form.location_out_id = stock_location_a_1 putaway_form.company_id = self.company_b with self.assertRaises(UserError): putaway_form.save()
def test_orderpoint_1(self): """As a user of company A, create an orderpoint for company B. Check itsn't possible to use a warehouse of companny A""" product = self.env['product.product'].create({ 'type': 'product', 'name': 'shared product', }) orderpoint = Form(self.env['stock.warehouse.orderpoint'].with_user( self.user_a)) orderpoint.company_id = self.company_b orderpoint.warehouse_id = self.warehouse_b orderpoint.location_id = self.stock_location_a orderpoint.product_id = product with self.assertRaises(UserError): orderpoint.save() orderpoint.location_id = self.stock_location_b orderpoint = orderpoint.save() self.assertEqual(orderpoint.company_id, self.company_b)
def test_05_confirmation_on_delivery(self): """ Test when user tries to delivery expired lot, he/she gets a confirmation wizard. """ partner = self.env['res.partner'].create({ 'name': 'Cider & Son', 'company_id': self.env.ref('base.main_company').id, }) # Creates 3 lots (1 non-expired lot, 2 expired lots) lot_form = Form(self.LotObj) # Creates the lot. lot_form.name = 'good-apple-lot' lot_form.product_id = self.apple_product lot_form.company_id = self.env.company good_lot = lot_form.save() lot_form = Form(self.LotObj) # Creates the lot. lot_form.name = 'expired-apple-lot-01' lot_form.product_id = self.apple_product lot_form.company_id = self.env.company expired_lot_1 = lot_form.save() lot_form = Form(expired_lot_1) # Edits the lot to make it expired. lot_form.expiration_date = datetime.today() - timedelta(days=10) expired_lot_1 = lot_form.save() # Case #1: make a delivery with no expired lot. picking_form = Form(self.env['stock.picking']) picking_form.partner_id = partner picking_form.picking_type_id = self.env.ref('stock.picking_type_out') with picking_form.move_ids_without_package.new() as move: move.product_id = self.apple_product move.product_uom_qty = 4 # Saves and confirms it... delivery_1 = picking_form.save() delivery_1.action_confirm() # ... then create a move line with the non-expired lot and valids the picking. delivery_1.move_line_ids_without_package = [ (5, 0), (0, 0, { 'company_id': self.env.company.id, 'location_id': delivery_1.move_lines.location_id.id, 'location_dest_id': delivery_1.move_lines.location_dest_id.id, 'lot_id': good_lot.id, 'product_id': self.apple_product.id, 'product_uom_id': self.apple_product.uom_id.id, 'qty_done': 4, }) ] res = delivery_1.button_validate() # Validate a delivery for good products must not raise anything. self.assertEqual(res, True) # Case #2: make a delivery with one non-expired lot and one expired lot. picking_form = Form(self.env['stock.picking']) picking_form.partner_id = partner picking_form.picking_type_id = self.env.ref('stock.picking_type_out') with picking_form.move_ids_without_package.new() as move: move.product_id = self.apple_product move.product_uom_qty = 8 # Saves and confirms it... delivery_2 = picking_form.save() delivery_2.action_confirm() # ... then create a move line for the non-expired lot and for an expired # lot and valids the picking. delivery_2.move_line_ids_without_package = [ (5, 0), (0, 0, { 'company_id': self.env.company.id, 'location_id': delivery_2.move_lines.location_id.id, 'location_dest_id': delivery_2.move_lines.location_dest_id.id, 'lot_id': good_lot.id, 'product_id': self.apple_product.id, 'product_uom_id': self.apple_product.uom_id.id, 'qty_done': 4, }), (0, 0, { 'company_id': self.env.company.id, 'location_id': delivery_2.move_lines.location_id.id, 'location_dest_id': delivery_2.move_lines.location_dest_id.id, 'lot_id': expired_lot_1.id, 'product_id': self.apple_product.id, 'product_uom_id': self.apple_product.uom_id.id, 'qty_done': 4, }) ] res = delivery_2.button_validate() # Validate a delivery containing expired products must raise a confirmation wizard. self.assertNotEqual(res, True) self.assertEqual(res['res_model'], 'expiry.picking.confirmation') # Case #3: make a delivery with only on expired lot. picking_form = Form(self.env['stock.picking']) picking_form.partner_id = partner picking_form.picking_type_id = self.env.ref('stock.picking_type_out') with picking_form.move_ids_without_package.new() as move: move.product_id = self.apple_product move.product_uom_qty = 4 # Saves and confirms it... delivery_3 = picking_form.save() delivery_3.action_confirm() # ... then create two move lines with expired lot and valids the picking. delivery_3.move_line_ids_without_package = [ (5, 0), (0, 0, { 'company_id': self.env.company.id, 'location_id': delivery_3.move_lines.location_id.id, 'location_dest_id': delivery_3.move_lines.location_dest_id.id, 'lot_id': expired_lot_1.id, 'product_id': self.apple_product.id, 'product_uom_id': self.apple_product.uom_id.id, 'qty_done': 4, }) ] res = delivery_3.button_validate() # Validate a delivery containing expired products must raise a confirmation wizard. self.assertNotEqual(res, True) self.assertEqual(res['res_model'], 'expiry.picking.confirmation')