mirror of
https://gitlab.com/hibou-io/hibou-odoo/suite.git
synced 2025-01-20 12:37:31 +02:00
Improve UI, allowing user to measure the catch weight in a specific unit of measure.
This UOM should be convertable (in the same category) as the normal stock UOM for the product. Example: If you want to sell 'units' of 50lbs then you should make a "50lbs" UOM in the Weight category and use that as the sale and purchase UOM, then your "Catch Weight UOM" can be the stock "lb(s)" UOM.
This commit is contained in:
@@ -9,7 +9,16 @@ _logger = logging.getLogger(__name__)
|
||||
class TestPicking(TransactionCase):
|
||||
def setUp(self):
|
||||
super(TestPicking, self).setUp()
|
||||
self.nominal_weight = 50.0
|
||||
self.partner1 = self.env.ref('base.res_partner_2')
|
||||
self.stock_location = self.env.ref('stock.stock_location_stock')
|
||||
self.ref_uom_id = self.env.ref('product.product_uom_kgm')
|
||||
self.product_uom_id = self.env['product.uom'].create({
|
||||
'name': '50 ref',
|
||||
'category_id': self.ref_uom_id.category_id.id,
|
||||
'uom_type': 'bigger',
|
||||
'factor_inv': self.nominal_weight,
|
||||
})
|
||||
self.product1 = self.env['product.product'].create({
|
||||
'name': 'Product 1',
|
||||
'type': 'product',
|
||||
@@ -17,13 +26,10 @@ class TestPicking(TransactionCase):
|
||||
'list_price': 100.0,
|
||||
'standard_price': 50.0,
|
||||
'taxes_id': [(5, 0, 0)],
|
||||
'uom_id': self.product_uom_id.id,
|
||||
'uom_po_id': self.product_uom_id.id,
|
||||
'catch_weight_uom_id': self.ref_uom_id.id,
|
||||
})
|
||||
#self.product1 = self.env.ref('product.product_order_01')
|
||||
self.product1.write({
|
||||
'type': 'product',
|
||||
'tracking': 'serial',
|
||||
})
|
||||
self.stock_location = self.env.ref('stock.stock_location_stock')
|
||||
|
||||
|
||||
# def test_creation(self):
|
||||
@@ -50,12 +56,13 @@ class TestPicking(TransactionCase):
|
||||
# self.env['stock.quant']._update_available_quantity(self.productA, stock_location, 1.0, lot_id=lot)
|
||||
|
||||
def test_so_invoice(self):
|
||||
ratio = 0.8
|
||||
ref_weight = 45.0
|
||||
lot = self.env['stock.production.lot'].create({
|
||||
'product_id': self.product1.id,
|
||||
'name': '123456789',
|
||||
'catch_weight_ratio': ratio,
|
||||
'catch_weight': ref_weight,
|
||||
})
|
||||
self.assertAlmostEqual(lot.catch_weight_ratio, ref_weight / self.nominal_weight)
|
||||
self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 1.0, lot_id=lot)
|
||||
so = self.env['sale.order'].create({
|
||||
'partner_id': self.partner1.id,
|
||||
@@ -75,20 +82,20 @@ class TestPicking(TransactionCase):
|
||||
|
||||
inv_id = so.action_invoice_create()
|
||||
inv = self.env['account.invoice'].browse(inv_id)
|
||||
self.assertEqual(inv.amount_total, ratio * self.product1.list_price)
|
||||
self.assertAlmostEqual(inv.amount_total, lot.catch_weight_ratio * self.product1.list_price)
|
||||
|
||||
def test_so_invoice2(self):
|
||||
ratio1 = 0.8
|
||||
ratio2 = 1.1
|
||||
ref_weight1 = 45.0
|
||||
ref_weight2 = 51.0
|
||||
lot1 = self.env['stock.production.lot'].create({
|
||||
'product_id': self.product1.id,
|
||||
'name': '1-low',
|
||||
'catch_weight_ratio': ratio1,
|
||||
'catch_weight': ref_weight1,
|
||||
})
|
||||
lot2 = self.env['stock.production.lot'].create({
|
||||
'product_id': self.product1.id,
|
||||
'name': '1-high',
|
||||
'catch_weight_ratio': ratio2,
|
||||
'catch_weight': ref_weight2,
|
||||
})
|
||||
self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 1.0, lot_id=lot1)
|
||||
self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 1.0, lot_id=lot2)
|
||||
@@ -111,12 +118,12 @@ class TestPicking(TransactionCase):
|
||||
|
||||
inv_id = so.action_invoice_create()
|
||||
inv = self.env['account.invoice'].browse(inv_id)
|
||||
self.assertEqual(inv.amount_total, (ratio1 * self.product1.list_price) + (ratio2 * self.product1.list_price))
|
||||
self.assertAlmostEqual(inv.amount_total, self.product1.list_price * (lot1.catch_weight_ratio + lot2.catch_weight_ratio))
|
||||
|
||||
def test_po_invoice(self):
|
||||
ratio1 = 0.8
|
||||
ratio2 = 1.1
|
||||
ratios = (ratio1, ratio2)
|
||||
ref_weight1 = 45.0
|
||||
ref_weight2 = 51.0
|
||||
weights = (ref_weight1, ref_weight2)
|
||||
price = self.product1.standard_price
|
||||
po = self.env['purchase.order'].create({
|
||||
'partner_id': self.partner1.id,
|
||||
@@ -135,7 +142,7 @@ class TestPicking(TransactionCase):
|
||||
|
||||
picking = po.picking_ids
|
||||
for i, line in enumerate(picking.move_lines.move_line_ids):
|
||||
line.write({'lot_name': str(i), 'qty_done': 1.0, 'lot_catch_weight_ratio': ratios[i]})
|
||||
line.write({'lot_name': str(i), 'qty_done': 1.0, 'catch_weight': weights[i]})
|
||||
picking.button_validate()
|
||||
self.assertEqual(picking.state, 'done')
|
||||
|
||||
@@ -147,6 +154,5 @@ class TestPicking(TransactionCase):
|
||||
inv.purchase_order_change()
|
||||
self.assertEqual(len(inv.invoice_line_ids), 1)
|
||||
self.assertEqual(inv.invoice_line_ids.quantity, 2.0)
|
||||
self.assertEqual(inv.amount_total, (ratio1 * price) + (ratio2 * price))
|
||||
|
||||
self.assertAlmostEqual(inv.amount_total, price * sum(w / self.nominal_weight for w in weights))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user