mirror of
https://github.com/OCA/stock-logistics-warehouse.git
synced 2025-01-21 14:27:28 +02:00
[IMP] Adds the glue which fill in the product packaging in stock
When a sale order is confirmed and product packaging is filled in sale order line(s), the information is propagated through procurement orders and stock moves. This is conditioned by a parameter on procurement rule.
This commit is contained in:
committed by
Thomas Binsfeld
parent
6fa1e022d4
commit
5d2c71c85f
@@ -1,7 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2015-2017 ACSONE SA/NV (<http://acsone.eu>)
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
from odoo import api, models
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class ProcurementOrder(models.Model):
|
||||
@@ -17,7 +17,7 @@ class ProcurementOrder(models.Model):
|
||||
seller = self.product_id._select_seller(
|
||||
partner_id=supplier.name,
|
||||
quantity=res['product_qty'],
|
||||
date=po.date_order and po.date_order[:10],
|
||||
date=po.date_order and fields.Date.from_string(po.date_order),
|
||||
uom_id=self.product_id.uom_po_id)
|
||||
if seller.packaging_id:
|
||||
res['packaging_id'] = seller.packaging_id.id
|
||||
|
||||
@@ -43,44 +43,49 @@ class PurchaseOrderLine(models.Model):
|
||||
return self.product_id._select_seller(
|
||||
partner_id=self.order_id.partner_id,
|
||||
quantity=self.product_qty,
|
||||
date=self.order_id.date_order and self.order_id.date_order[:10],
|
||||
date=self.order_id.date_order and
|
||||
fields.Date.from_string(self.order_id.date_order),
|
||||
uom_id=self.product_uom)
|
||||
|
||||
@api.one
|
||||
@api.multi
|
||||
@api.depends('product_purchase_uom_id', 'product_purchase_qty')
|
||||
def _compute_product_qty(self):
|
||||
"""
|
||||
Compute the total quantity
|
||||
"""
|
||||
uom_obj = self.env['product.uom']
|
||||
to_uom = uom_obj.search(
|
||||
[('category_id', '=', self.product_purchase_uom_id.category_id.id),
|
||||
('uom_type', '=', 'reference')], limit=1)
|
||||
if not self.product_purchase_uom_id:
|
||||
return
|
||||
self.product_qty = self.product_purchase_uom_id._compute_quantity(
|
||||
self.product_purchase_qty,
|
||||
to_uom)
|
||||
for line in self:
|
||||
uom_obj = self.env['product.uom']
|
||||
to_uom = uom_obj.search(
|
||||
[('category_id',
|
||||
'=',
|
||||
line.product_purchase_uom_id.category_id.id),
|
||||
('uom_type', '=', 'reference')], limit=1)
|
||||
if not line.product_purchase_uom_id:
|
||||
return
|
||||
line.product_qty = line.product_purchase_uom_id._compute_quantity(
|
||||
line.product_purchase_qty,
|
||||
to_uom)
|
||||
|
||||
@api.one
|
||||
@api.multi
|
||||
def _inverse_product_qty(self):
|
||||
""" If product_quantity is set compute the purchase_qty
|
||||
"""
|
||||
if self.product_id:
|
||||
supplier = self._get_product_seller()
|
||||
if supplier:
|
||||
product_purchase_uom = supplier.min_qty_uom_id
|
||||
uom_obj = self.env['product.uom']
|
||||
from_uom = uom_obj.search(
|
||||
[('category_id', '=',
|
||||
product_purchase_uom.category_id.id),
|
||||
('uom_type', '=', 'reference')], limit=1)
|
||||
self.product_purchase_qty = from_uom._compute_quantity(
|
||||
self.product_qty,
|
||||
product_purchase_uom)
|
||||
self.product_purchase_uom_id = product_purchase_uom.id
|
||||
else:
|
||||
self.product_purchase_qty = self.product_qty
|
||||
for line in self:
|
||||
if line.product_id:
|
||||
supplier = line._get_product_seller()
|
||||
if supplier:
|
||||
product_purchase_uom = supplier.min_qty_uom_id
|
||||
uom_obj = self.env['product.uom']
|
||||
from_uom = uom_obj.search(
|
||||
[('category_id', '=',
|
||||
product_purchase_uom.category_id.id),
|
||||
('uom_type', '=', 'reference')], limit=1)
|
||||
line.product_purchase_qty = from_uom._compute_quantity(
|
||||
line.product_qty,
|
||||
product_purchase_uom)
|
||||
line.product_purchase_uom_id = product_purchase_uom.id
|
||||
else:
|
||||
line.product_purchase_qty = line.product_qty
|
||||
|
||||
@api.onchange("packaging_id")
|
||||
def _onchange_packaging_id(self):
|
||||
@@ -136,7 +141,7 @@ class PurchaseOrderLine(models.Model):
|
||||
if res.get('domain'):
|
||||
res['domain'].update(domain)
|
||||
else:
|
||||
res['domain'] = domain
|
||||
res['domain'] = domain # pragma: no cover not aware of super
|
||||
return res
|
||||
|
||||
@api.multi
|
||||
|
||||
@@ -22,6 +22,11 @@ class TestPurchaseOrderLine(common.TransactionCase):
|
||||
'uom_id': self.env.ref('product.product_uom_dozen').id,
|
||||
'name': 'Packaging Dozen'}
|
||||
)
|
||||
self.product_packaging_unit = self.env['product.packaging'].create(
|
||||
{'product_tmpl_id': self.product_tmpl_id.id,
|
||||
'uom_id': self.env.ref('product.product_uom_unit').id,
|
||||
'name': 'Packaging Unit'}
|
||||
)
|
||||
self.product_uom_8 = self.env['product.uom'].create(
|
||||
{'category_id': self.env.ref('product.product_uom_categ_unit').id,
|
||||
'name': 'COL8',
|
||||
@@ -79,3 +84,54 @@ class TestPurchaseOrderLine(common.TransactionCase):
|
||||
self.assertEqual(sm.product_uom.id,
|
||||
self.env.ref('product.product_uom_dozen').id)
|
||||
self.assertAlmostEqual(sm.product_uom_qty, 16)
|
||||
|
||||
def test_po_line_no_product(self):
|
||||
self.product_supplier_info.min_qty_uom_id = self.product_uom_8
|
||||
self.product_supplier_info.min_qty = 2
|
||||
self.product_supplier_info.packaging_id = self.product_packaging_dozen
|
||||
|
||||
po = self.env['purchase.order'].create(
|
||||
{'partner_id': self.product_supplier_info.name.id})
|
||||
po_line = po.order_line.new({
|
||||
'product_id': self.product_tmpl_id.product_variant_id,
|
||||
'product_purchase_qty': 1.0,
|
||||
'product_purchase_uom_id':
|
||||
po.order_line._default_product_purchase_uom_id(),
|
||||
'order_id': po
|
||||
})
|
||||
po_line.onchange_product_id()
|
||||
po_line.product_id = None
|
||||
po_line.product_qty = 2.0
|
||||
self.assertEqual(
|
||||
2.0,
|
||||
po_line.product_purchase_qty,
|
||||
'The purchase quantity is not well set'
|
||||
)
|
||||
|
||||
def test_po_line_change_packaging(self):
|
||||
self.product_supplier_info.min_qty_uom_id = self.product_uom_8
|
||||
self.product_supplier_info.min_qty = 2
|
||||
self.product_supplier_info.packaging_id = self.product_packaging_dozen
|
||||
|
||||
po = self.env['purchase.order'].create(
|
||||
{'partner_id': self.product_supplier_info.name.id})
|
||||
po_line = po.order_line.new({
|
||||
'product_id': self.product_tmpl_id.product_variant_id,
|
||||
'product_purchase_qty': 1.0,
|
||||
'product_purchase_uom_id':
|
||||
po.order_line._default_product_purchase_uom_id(),
|
||||
'order_id': po
|
||||
})
|
||||
po_line.onchange_product_id()
|
||||
self.assertEquals(
|
||||
self.product_packaging_dozen.uom_id,
|
||||
po_line.product_uom,
|
||||
'The UOM Unit is not well set'
|
||||
)
|
||||
po_line.packaging_id = self.product_packaging_unit
|
||||
po_line._onchange_packaging_id()
|
||||
self.assertEquals(
|
||||
self.product_packaging_unit.uom_id,
|
||||
po_line.product_uom,
|
||||
'The product uom is not well set'
|
||||
)
|
||||
|
||||
@@ -22,10 +22,15 @@
|
||||
<field name="inherit_id" ref="product.product_supplierinfo_form_view"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="min_qty" position="after">
|
||||
<field name="min_qty_uom_id" groups="product.group_uom"/>
|
||||
<span> x <field name="min_qty_uom_id" groups="product.group_uom"/></span>
|
||||
</field>
|
||||
<field name="product_uom" position="before">
|
||||
<span> of </span>
|
||||
</field>
|
||||
<field name="product_uom" position="after">
|
||||
<field name="packaging_id" domain="[('product_tmpl_id', '=', product_tmpl_id)]" groups="product.group_stock_packaging"/>
|
||||
<div>
|
||||
using package <field name="packaging_id" domain="[('product_tmpl_id', '=', product_tmpl_id)]" groups="product.group_stock_packaging"/>
|
||||
</div>
|
||||
</field>
|
||||
<field name="delay" position="after">
|
||||
<field name="product_tmpl_id" invisible="1" required="False"/>
|
||||
|
||||
Reference in New Issue
Block a user