123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251 |
- # -*- coding: utf-8 -*-
- # Part of Odoo. See LICENSE file for full copyright and licensing details.
- from odoo.addons.stock.tests.common import TestStockCommon
- class TestReplenishWizard(TestStockCommon):
- @classmethod
- def setUpClass(cls):
- super().setUpClass()
- cls.vendor = cls.env['res.partner'].create(dict(name='The Replenisher'))
- cls.product1_price = 500
- # Create a supplier info witch the previous vendor
- cls.supplierinfo = cls.env['product.supplierinfo'].create({
- 'partner_id': cls.vendor.id,
- 'price': cls.product1_price,
- })
- # Create a product with the 'buy' route and
- # the 'supplierinfo' prevously created
- cls.product1 = cls.env['product.product'].create({
- 'name': 'product a',
- 'type': 'product',
- 'categ_id': cls.env.ref('product.product_category_all').id,
- 'seller_ids': [(4, cls.supplierinfo.id, 0)],
- 'route_ids': [(4, cls.env.ref('purchase_stock.route_warehouse0_buy').id, 0)],
- })
- # Additional Values required by the replenish wizard
- cls.uom_unit = cls.env.ref('uom.product_uom_unit')
- cls.wh = cls.env['stock.warehouse'].search([('company_id', '=', cls.env.user.id)], limit=1)
- def test_replenish_buy_1(self):
- """ Set a quantity to replenish via the "Buy" route and check if
- a purchase order is created with the correct values
- """
- self.product_uom_qty = 42
- replenish_wizard = self.env['product.replenish'].create({
- 'product_id': self.product1.id,
- 'product_tmpl_id': self.product1.product_tmpl_id.id,
- 'product_uom_id': self.uom_unit.id,
- 'quantity': self.product_uom_qty,
- 'warehouse_id': self.wh.id,
- })
- replenish_wizard.launch_replenishment()
- last_po_id = self.env['purchase.order'].search([
- ('origin', 'ilike', '%Manual Replenishment%'),
- ('partner_id', '=', self.vendor.id)
- ])[-1]
- self.assertTrue(last_po_id, 'Purchase Order not found')
- order_line = last_po_id.order_line.search([('product_id', '=', self.product1.id)])
- self.assertTrue(order_line, 'The product is not in the Purchase Order')
- self.assertEqual(order_line.product_qty, self.product_uom_qty, 'Quantities does not match')
- self.assertEqual(order_line.price_unit, self.product1_price, 'Prices does not match')
- def test_chose_supplier_1(self):
- """ Choose supplier based on the ordered quantity and minimum price
- replenish 10
- 1)seq1 vendor1 140 min qty 1
- 2)seq2 vendor1 100 min qty 10
- -> 2) should be chosen
- """
- product_to_buy = self.env['product.product'].create({
- 'name': "Furniture Service",
- 'type': 'product',
- 'categ_id': self.env.ref('product.product_category_all').id,
- 'route_ids': [(4, self.env.ref('purchase_stock.route_warehouse0_buy').id, 0)],
- })
- vendor1 = self.env['res.partner'].create({'name': 'vendor1', 'email': 'from.test@example.com'})
- supplierinfo1 = self.env['product.supplierinfo'].create({
- 'product_tmpl_id': product_to_buy.product_tmpl_id.id,
- 'partner_id': vendor1.id,
- 'min_qty': 1,
- 'price': 140,
- 'sequence': 1,
- })
- supplierinfo2 = self.env['product.supplierinfo'].create({
- 'product_tmpl_id': product_to_buy.product_tmpl_id.id,
- 'partner_id': vendor1.id,
- 'min_qty': 10,
- 'price': 100,
- 'sequence': 2,
- })
- replenish_wizard = self.env['product.replenish'].create({
- 'product_id': product_to_buy.id,
- 'product_tmpl_id': product_to_buy.product_tmpl_id.id,
- 'product_uom_id': self.uom_unit.id,
- 'quantity': 10,
- 'warehouse_id': self.wh.id,
- })
- replenish_wizard.launch_replenishment()
- last_po_id = self.env['purchase.order'].search([
- ('origin', 'ilike', '%Manual Replenishment%'),
- ])[-1]
- self.assertEqual(last_po_id.partner_id, vendor1)
- self.assertEqual(last_po_id.order_line.price_unit, 100)
- def test_chose_supplier_2(self):
- """ Choose supplier based on the ordered quantity and minimum price
- replenish 10
- 1)seq1 vendor1 140 min qty 1
- 2)seq2 vendor2 90 min qty 10
- 3)seq3 vendor1 100 min qty 10
- -> 3) should be chosen
- """
- product_to_buy = self.env['product.product'].create({
- 'name': "Furniture Service",
- 'type': 'product',
- 'categ_id': self.env.ref('product.product_category_all').id,
- 'route_ids': [(4, self.env.ref('purchase_stock.route_warehouse0_buy').id, 0)],
- })
- vendor1 = self.env['res.partner'].create({'name': 'vendor1', 'email': 'from.test@example.com'})
- vendor2 = self.env['res.partner'].create({'name': 'vendor2', 'email': 'from.test2@example.com'})
- supplierinfo1 = self.env['product.supplierinfo'].create({
- 'product_tmpl_id': product_to_buy.product_tmpl_id.id,
- 'partner_id': vendor1.id,
- 'min_qty': 1,
- 'price': 140,
- 'sequence': 1,
- })
- supplierinfo2 = self.env['product.supplierinfo'].create({
- 'product_tmpl_id': product_to_buy.product_tmpl_id.id,
- 'partner_id': vendor2.id,
- 'min_qty': 10,
- 'price': 90,
- 'sequence': 2,
- })
- supplierinfo3 = self.env['product.supplierinfo'].create({
- 'product_tmpl_id': product_to_buy.product_tmpl_id.id,
- 'partner_id': vendor1.id,
- 'min_qty': 10,
- 'price': 100,
- 'sequence': 3,
- })
- replenish_wizard = self.env['product.replenish'].create({
- 'product_id': product_to_buy.id,
- 'product_tmpl_id': product_to_buy.product_tmpl_id.id,
- 'product_uom_id': self.uom_unit.id,
- 'quantity': 10,
- 'warehouse_id': self.wh.id,
- })
- replenish_wizard.launch_replenishment()
- last_po_id = self.env['purchase.order'].search([
- ('origin', 'ilike', '%Manual Replenishment%'),
- ])[-1]
- self.assertEqual(last_po_id.partner_id, vendor1)
- self.assertEqual(last_po_id.order_line.price_unit, 100)
- def test_chose_supplier_3(self):
- """ Choose supplier based on the ordered quantity and minimum price
- replenish 10
- 1)seq2 vendor1 50
- 2)seq1 vendor2 50
- -> 2) should be chosen
- """
- product_to_buy = self.env['product.product'].create({
- 'name': "Furniture Service",
- 'type': 'product',
- 'categ_id': self.env.ref('product.product_category_all').id,
- 'route_ids': [(4, self.env.ref('purchase_stock.route_warehouse0_buy').id, 0)],
- })
- vendor1 = self.env['res.partner'].create({'name': 'vendor1', 'email': 'from.test@example.com'})
- vendor2 = self.env['res.partner'].create({'name': 'vendor2', 'email': 'from.test2@example.com'})
- supplierinfo1 = self.env['product.supplierinfo'].create({
- 'product_tmpl_id': product_to_buy.product_tmpl_id.id,
- 'partner_id': vendor1.id,
- 'price': 50,
- 'sequence': 2,
- })
- supplierinfo2 = self.env['product.supplierinfo'].create({
- 'product_tmpl_id': product_to_buy.product_tmpl_id.id,
- 'partner_id': vendor2.id,
- 'price': 50,
- 'sequence': 1,
- })
- replenish_wizard = self.env['product.replenish'].create({
- 'product_id': product_to_buy.id,
- 'product_tmpl_id': product_to_buy.product_tmpl_id.id,
- 'product_uom_id': self.uom_unit.id,
- 'quantity': 10,
- 'warehouse_id': self.wh.id,
- })
- replenish_wizard.launch_replenishment()
- last_po_id = self.env['purchase.order'].search([
- ('origin', 'ilike', '%Manual Replenishment%'),
- ])[-1]
- self.assertEqual(last_po_id.partner_id, vendor2)
- def test_chose_supplier_4(self):
- """ Choose supplier based on the ordered quantity and minimum price
- replenish 10
- 1)seq1 vendor1 100 min qty 2
- 2)seq2 vendor1 60 min qty 10
- 2)seq3 vendor1 80 min qty 5
- -> 2) should be chosen
- """
- product_to_buy = self.env['product.product'].create({
- 'name': "Furniture Service",
- 'type': 'product',
- 'categ_id': self.env.ref('product.product_category_all').id,
- 'route_ids': [(4, self.env.ref('purchase_stock.route_warehouse0_buy').id, 0)],
- })
- vendor1 = self.env['res.partner'].create({'name': 'vendor1', 'email': 'from.test@example.com'})
- supplierinfo1 = self.env['product.supplierinfo'].create({
- 'partner_id': vendor1.id,
- 'price': 100,
- 'product_tmpl_id': product_to_buy.product_tmpl_id.id,
- 'min_qty': 2
- })
- supplierinfo2 = self.env['product.supplierinfo'].create({
- 'partner_id': vendor1.id,
- 'price': 60,
- 'product_tmpl_id': product_to_buy.product_tmpl_id.id,
- 'min_qty': 10
- })
- supplierinfo3 = self.env['product.supplierinfo'].create({
- 'partner_id': vendor1.id,
- 'price': 80,
- 'product_tmpl_id': product_to_buy.product_tmpl_id.id,
- 'min_qty': 5
- })
- replenish_wizard = self.env['product.replenish'].create({
- 'product_id': product_to_buy.id,
- 'product_tmpl_id': product_to_buy.product_tmpl_id.id,
- 'product_uom_id': self.uom_unit.id,
- 'quantity': 10,
- 'warehouse_id': self.wh.id,
- })
- replenish_wizard.launch_replenishment()
- last_po_id = self.env['purchase.order'].search([
- ('origin', 'ilike', '%Manual Replenishment%'),
- ])[-1]
- self.assertEqual(last_po_id.partner_id, vendor1)
- self.assertEqual(last_po_id.order_line.price_unit, 60)
|