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)
Exemple #2
0
 def test_archive_product_2(self):
     """Archiving a product should archive its reordering rules"""
     self.assertTrue(self.product_3.active)
     orderpoint_form = Form(self.env['stock.warehouse.orderpoint'])
     orderpoint_form.product_id = self.product_3
     orderpoint_form.location_id = self.env.ref(
         'stock.stock_location_stock')
     orderpoint_form.product_min_qty = 0.0
     orderpoint_form.product_max_qty = 5.0
     orderpoint = orderpoint_form.save()
     self.assertTrue(orderpoint.active)
     self.product_3.active = False
     self.assertFalse(orderpoint.active)
 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 _create_move_quantities(self, qty_to_process, components, warehouse):
        """ Helper to creates moves in order to update the quantities of components
        on a specific warehouse. This ensure that all compute fields are triggered.
        The structure of qty_to_process should be the following :

         qty_to_process = {
            component: (qty, uom),
            ...
        }
        """
        for comp in components:
            f = Form(self.env['stock.move'])
            f.name = 'Test Receipt Components'
            f.location_id = self.env.ref('stock.stock_location_suppliers')
            f.location_dest_id = warehouse.lot_stock_id
            f.product_id = comp
            f.product_uom = qty_to_process[comp][1]
            f.product_uom_qty = qty_to_process[comp][0]
            move = f.save()
            move._action_confirm()
            move._action_assign()
            move_line = move.move_line_ids[0]
            move_line.qty_done = qty_to_process[comp][0]
            move._action_done()
    def test_replenishment_report_1(self):
        self.product_replenished = self.env['product.product'].create({
            'name':
            'Security razor',
            'type':
            'product',
            'categ_id':
            self.env.ref('product.product_category_all').id,
        })
        # get auto-created pull rule from when warehouse is created
        self.wh.reception_route_id.rule_ids.unlink()
        self.env['stock.rule'].create({
            'name':
            'Rule Supplier',
            'route_id':
            self.wh.reception_route_id.id,
            'location_id':
            self.wh.lot_stock_id.id,
            'location_src_id':
            self.env.ref('stock.stock_location_suppliers').id,
            'action':
            'pull',
            'delay':
            1.0,
            'procure_method':
            'make_to_stock',
            'picking_type_id':
            self.wh.in_type_id.id,
        })
        delivery_picking = self.env['stock.picking'].create({
            'location_id':
            self.wh.lot_stock_id.id,
            'location_dest_id':
            self.ref('stock.stock_location_customers'),
            'picking_type_id':
            self.ref('stock.picking_type_out'),
        })
        self.env['stock.move'].create({
            'name':
            'Delivery',
            'product_id':
            self.product_replenished.id,
            'product_uom_qty':
            500.0,
            'product_uom':
            self.uom_unit.id,
            'location_id':
            self.wh.lot_stock_id.id,
            'location_dest_id':
            self.ref('stock.stock_location_customers'),
            'picking_id':
            delivery_picking.id,
        })
        delivery_picking.action_confirm()

        # Trigger the manual orderpoint creation for missing product
        self.env['stock.move'].flush()
        self.env['stock.warehouse.orderpoint'].action_open_orderpoints()

        orderpoint = self.env['stock.warehouse.orderpoint'].search([
            ('product_id', '=', self.product_replenished.id)
        ])
        self.assertTrue(orderpoint)
        self.assertEqual(orderpoint.location_id, self.wh.lot_stock_id)
        self.assertEqual(orderpoint.qty_to_order, 500.0)
        orderpoint.action_replenish()
        self.env['stock.warehouse.orderpoint'].action_open_orderpoints()

        move = self.env['stock.move'].search([
            ('product_id', '=', self.product_replenished.id),
            ('location_dest_id', '=', self.wh.lot_stock_id.id)
        ])
        # Simulate a supplier delay
        move.date = fields.datetime.now() + timedelta(days=1)
        orderpoint = self.env['stock.warehouse.orderpoint'].search([
            ('product_id', '=', self.product_replenished.id)
        ])
        self.assertFalse(orderpoint)

        orderpoint_form = Form(self.env['stock.warehouse.orderpoint'])
        orderpoint_form.product_id = self.product_replenished
        orderpoint_form.location_id = self.wh.lot_stock_id
        orderpoint = orderpoint_form.save()

        self.assertEqual(orderpoint.qty_to_order, 0.0)
        self.env['stock.warehouse.orderpoint'].action_open_orderpoints()
        self.assertEqual(orderpoint.qty_to_order, 0.0)