mirror of
https://github.com/OCA/stock-logistics-warehouse.git
synced 2025-01-21 14:27:28 +02:00
[MIG] packaging_uom, purchase_packaging, sale_packaging: Migrated to 10.0
This commit is contained in:
committed by
Thomas Binsfeld
parent
d4b755d3a8
commit
6fa1e022d4
@@ -1,5 +1,6 @@
|
||||
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
|
||||
:alt: License: AGPL-3
|
||||
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
|
||||
:alt: License: AGPL-3
|
||||
|
||||
Purchase Packaging
|
||||
==================
|
||||
@@ -10,15 +11,6 @@ Purchase Packaging
|
||||
- On purchase order line compute the quantity with the quantity and unit of
|
||||
measure
|
||||
|
||||
|
||||
|
||||
Installation
|
||||
============
|
||||
|
||||
To install this module, you need to:
|
||||
|
||||
* Click on install button
|
||||
|
||||
Configuration
|
||||
=============
|
||||
|
||||
@@ -32,22 +24,26 @@ To configure this module, you need to:
|
||||
Usage
|
||||
=====
|
||||
|
||||
For further information, please visit:
|
||||
|
||||
* https://www.odoo.com/forum/help-1
|
||||
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
|
||||
:alt: Try me on Runbot
|
||||
:target: https://runbot.odoo-community.org/runbot/153/10.0
|
||||
|
||||
Bug Tracker
|
||||
===========
|
||||
|
||||
Bugs are tracked on `GitHub Issues <https://github.com/OCA/stock-logistics-warehouse/issues>`_.
|
||||
In case of trouble, please check there if your issue has already been reported.
|
||||
If you spotted it first, help us smashing it by providing a detailed and welcomed feedback
|
||||
`here <https://github.com/OCA/stock-logistics-warehouse/issues/new?body=module:%20purchase_packaging%0Aversion:%208.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
|
||||
|
||||
Bugs are tracked on `GitHub Issues
|
||||
<https://github.com/OCA/stock-logistics-warehouse/issues>`_. In case of trouble, please
|
||||
check there if your issue has already been reported. If you spotted it first,
|
||||
help us smashing it by providing a detailed and welcomed feedback.
|
||||
|
||||
Credits
|
||||
=======
|
||||
|
||||
Images
|
||||
------
|
||||
|
||||
* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.
|
||||
|
||||
Contributors
|
||||
------------
|
||||
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
# -*- 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 . import models
|
||||
|
||||
|
||||
def set_product_purchase_qty(cr, registry):
|
||||
cr.execute("""update purchase_order_line
|
||||
set product_purchase_qty = product_qty""")
|
||||
from .hooks import post_init_hook
|
||||
|
||||
23
purchase_packaging/__manifest__.py
Executable file
23
purchase_packaging/__manifest__.py
Executable file
@@ -0,0 +1,23 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2015-2017 ACSONE SA/NV (<http://acsone.eu>)
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
{
|
||||
"name": "Purchase Packaging",
|
||||
"version": "10.0.1.0.0",
|
||||
"author": 'ACSONE SA/NV, '
|
||||
'Odoo Community Association (OCA)',
|
||||
"category": "Warehouse",
|
||||
"website": "http://www.acsone.eu",
|
||||
'summary': "In purchase, use package",
|
||||
"depends": ["product",
|
||||
"purchase",
|
||||
"packaging_uom",
|
||||
],
|
||||
"data": ["views/product_supplier_info_view.xml",
|
||||
"views/purchase_order_view.xml",
|
||||
"views/purchase_order_line_view.xml",
|
||||
],
|
||||
"post_init_hook": "post_init_hook",
|
||||
"license": "AGPL-3",
|
||||
"installable": True,
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# Authors: Laetitia Gangloff
|
||||
# Copyright (c) 2015 Acsone SA/NV (http://www.acsone.eu)
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
{
|
||||
"name": "Purchase Packaging",
|
||||
"version": "0.1",
|
||||
'author': "Acsone, Odoo Community Association (OCA)",
|
||||
"category": "Other",
|
||||
"website": "http://www.acsone.eu",
|
||||
'summary': "In purchase, use package",
|
||||
"depends": ["product",
|
||||
"purchase",
|
||||
"packaging_uom",
|
||||
],
|
||||
"data": ["views/product_views.xml",
|
||||
"views/purchase_views.xml",
|
||||
],
|
||||
"post_init_hook": "set_product_purchase_qty",
|
||||
"license": "AGPL-3",
|
||||
"installable": True,
|
||||
"application": False,
|
||||
}
|
||||
8
purchase_packaging/hooks.py
Executable file
8
purchase_packaging/hooks.py
Executable file
@@ -0,0 +1,8 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2015-2017 ACSONE SA/NV (<http://acsone.eu>)
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
|
||||
def post_init_hook(cr, registry):
|
||||
cr.execute("""update purchase_order_line
|
||||
set product_purchase_qty = product_qty""")
|
||||
@@ -1,4 +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 . import product
|
||||
from . import purchase
|
||||
from . import product_supplier_info
|
||||
from . import purchase_order_line
|
||||
from . import procurement_order
|
||||
|
||||
30
purchase_packaging/models/procurement_order.py
Normal file
30
purchase_packaging/models/procurement_order.py
Normal file
@@ -0,0 +1,30 @@
|
||||
# -*- 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
|
||||
|
||||
|
||||
class ProcurementOrder(models.Model):
|
||||
_inherit = 'procurement.order'
|
||||
|
||||
@api.multi
|
||||
def _prepare_purchase_order_line(self, po, supplier):
|
||||
""" add packaging and update product_uom/quantity if necessary
|
||||
"""
|
||||
self.ensure_one()
|
||||
res = super(ProcurementOrder, self)._prepare_purchase_order_line(
|
||||
po, supplier)
|
||||
seller = self.product_id._select_seller(
|
||||
partner_id=supplier.name,
|
||||
quantity=res['product_qty'],
|
||||
date=po.date_order and po.date_order[:10],
|
||||
uom_id=self.product_id.uom_po_id)
|
||||
if seller.packaging_id:
|
||||
res['packaging_id'] = seller.packaging_id.id
|
||||
new_uom_id = seller.product_uom
|
||||
if new_uom_id.id != res['product_uom']:
|
||||
res['product_uom'] = new_uom_id
|
||||
qty = self.product_uom._compute_quantity(
|
||||
self.product_qty, new_uom_id)
|
||||
res['product_qty'] = max(qty, seller.min_qty)
|
||||
return res
|
||||
@@ -1,49 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# Authors: Laetitia Gangloff
|
||||
# Copyright (c) 2015 Acsone SA/NV (http://www.acsone.eu)
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
|
||||
from openerp import api, fields, models
|
||||
|
||||
|
||||
class ProductSupplierinfo(models.Model):
|
||||
_inherit = "product.supplierinfo"
|
||||
|
||||
@api.model
|
||||
def _default_min_qty_uom_id(self):
|
||||
return self.env.ref('product.product_uom_unit')
|
||||
|
||||
packaging_id = fields.Many2one('product.packaging', 'Logisitical Units')
|
||||
product_uom = fields.Many2one(compute='_compute_product_uom',
|
||||
string="Supplier Unit of Measure",
|
||||
readonly=True)
|
||||
min_qty_uom_id = fields.Many2one('product.uom',
|
||||
'Minimal Unit of Measure Quantity',
|
||||
required=True,
|
||||
default=_default_min_qty_uom_id)
|
||||
|
||||
@api.one
|
||||
@api.depends('product_tmpl_id', 'packaging_id')
|
||||
def _compute_product_uom(self):
|
||||
""" Set product_uom as a computed field instead of a related field.
|
||||
To use uom of link packaging
|
||||
"""
|
||||
self.product_uom = self.packaging_id.uom_id or \
|
||||
self.product_tmpl_id.uom_po_id
|
||||
39
purchase_packaging/models/product_supplier_info.py
Normal file
39
purchase_packaging/models/product_supplier_info.py
Normal file
@@ -0,0 +1,39 @@
|
||||
# -*- 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, fields, models
|
||||
|
||||
|
||||
class ProductSupplierinfo(models.Model):
|
||||
_inherit = "product.supplierinfo"
|
||||
|
||||
@api.model
|
||||
def _default_min_qty_uom_id(self):
|
||||
return self.env.ref('product.product_uom_unit')
|
||||
|
||||
packaging_id = fields.Many2one(
|
||||
'product.packaging',
|
||||
'Logisitical Units'
|
||||
)
|
||||
product_uom = fields.Many2one(
|
||||
compute='_compute_product_uom',
|
||||
string="Supplier Unit of Measure",
|
||||
related=False
|
||||
)
|
||||
min_qty_uom_id = fields.Many2one(
|
||||
'product.uom',
|
||||
'Minimal Unit of Measure Quantity',
|
||||
required=True,
|
||||
default=_default_min_qty_uom_id
|
||||
)
|
||||
|
||||
@api.multi
|
||||
@api.depends('product_tmpl_id', 'packaging_id')
|
||||
def _compute_product_uom(self):
|
||||
""" Set product_uom as a computed field instead of a related field.
|
||||
To use uom of link packaging
|
||||
"""
|
||||
for rec in self:
|
||||
rec.product_uom = rec.packaging_id.uom_id or \
|
||||
rec.product_id.uom_po_id or \
|
||||
rec.product_tmpl_id.uom_po_id
|
||||
@@ -1,239 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# Authors: Laetitia Gangloff
|
||||
# Copyright (c) 2015 Acsone SA/NV (http://www.acsone.eu)
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
|
||||
from openerp import api, fields, models
|
||||
import openerp.addons.decimal_precision as dp
|
||||
|
||||
|
||||
class PurchaseOrder(models.Model):
|
||||
_inherit = "purchase.order"
|
||||
|
||||
@api.cr_uid_context
|
||||
def _prepare_order_line_move(self, cr, uid, order, order_line, picking_id,
|
||||
group_id, context=None):
|
||||
""" Set product_packaging on stock move
|
||||
"""
|
||||
result = super(PurchaseOrder, self)._prepare_order_line_move(
|
||||
cr, uid, order, order_line, picking_id, group_id,
|
||||
context=context)
|
||||
if order_line.packaging_id:
|
||||
for res in result:
|
||||
res['product_packaging'] = order_line.packaging_id.id
|
||||
return result
|
||||
|
||||
|
||||
class PurchaseOrderLine(models.Model):
|
||||
_inherit = "purchase.order.line"
|
||||
|
||||
@api.model
|
||||
def _default_product_purchase_uom_id(self):
|
||||
return self.env.ref('product.product_uom_unit')
|
||||
|
||||
product_tmpl_id = fields.Many2one(related='product_id.product_tmpl_id',
|
||||
comodel_name='product.template')
|
||||
packaging_id = fields.Many2one('product.packaging', 'Packaging')
|
||||
product_purchase_qty = fields.Float(
|
||||
'Purchase quantity',
|
||||
digits_compute=dp.get_precision('Product Unit of Measure'),
|
||||
required=True, default=lambda *a: 1.0)
|
||||
product_purchase_uom_id = fields.Many2one(
|
||||
'product.uom', 'Purchase Unit of Measure', required=True,
|
||||
default=_default_product_purchase_uom_id)
|
||||
product_qty = fields.Float(
|
||||
compute="_compute_product_qty", string='Quantity',
|
||||
inverse='_inverse_product_qty',)
|
||||
|
||||
@api.one
|
||||
@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)
|
||||
self.product_qty = uom_obj._compute_qty(
|
||||
self.product_purchase_uom_id.id,
|
||||
self.product_purchase_qty,
|
||||
to_uom.id)
|
||||
|
||||
@api.one
|
||||
def _inverse_product_qty(self):
|
||||
""" If product_quantity is set compute the purchase_qty
|
||||
"""
|
||||
if self.product_id and self.order_id.partner_id:
|
||||
for supplier in self.product_id.seller_ids:
|
||||
if (supplier.name.id == self.order_id.partner_id.id):
|
||||
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 = uom_obj._compute_qty(
|
||||
from_uom.id,
|
||||
self.product_qty,
|
||||
product_purchase_uom.id,)
|
||||
self.product_purchase_uom_id = product_purchase_uom.id
|
||||
break
|
||||
else:
|
||||
self.product_purchase_qty = self.product_qty
|
||||
|
||||
@api.onchange("packaging_id")
|
||||
def _onchange_packaging_id(self):
|
||||
if self.packaging_id:
|
||||
self.product_uom = self.packaging_id.uom_id
|
||||
|
||||
@api.cr_uid_context
|
||||
def onchange_product_id(self, cr, uid, ids, pricelist_id, product_id, qty,
|
||||
uom_id, partner_id, date_order=False,
|
||||
fiscal_position_id=False, date_planned=False,
|
||||
name=False, price_unit=False, state='draft',
|
||||
context=None):
|
||||
""" set domain on product_purchase_uom_id and packaging_id
|
||||
if there is no qty (first pass),
|
||||
set the first packagigng, purchase_uom and purchase_qty
|
||||
"""
|
||||
product_product = self.pool['product.product']
|
||||
product_purchase_qty = 0
|
||||
product_purchase_uom_id = False
|
||||
category_product_purchase_uom_id = False
|
||||
packaging_id = False
|
||||
new_uom_id = False
|
||||
domain = {}
|
||||
|
||||
if product_id and partner_id:
|
||||
product = product_product.browse(cr, uid, product_id,
|
||||
context=context)
|
||||
first = True
|
||||
packaging_ids = []
|
||||
po_uom_ids = []
|
||||
domain['packaging_id'] = [('id', 'in', packaging_ids)]
|
||||
domain['product_purchase_uom_id'] = [('id', 'in', po_uom_ids)]
|
||||
for supplier in product.seller_ids:
|
||||
if (supplier.name.id == partner_id):
|
||||
if first:
|
||||
product_purchase_qty = supplier.min_qty
|
||||
product_purchase_uom_id = supplier.min_qty_uom_id.id
|
||||
category_product_purchase_uom_id = \
|
||||
supplier.min_qty_uom_id.category_id.id
|
||||
new_uom_id = supplier.product_uom.id
|
||||
if supplier.packaging_id:
|
||||
packaging_id = supplier.packaging_id.id
|
||||
first = False
|
||||
po_uom_ids.append(supplier.min_qty_uom_id.id)
|
||||
if supplier.packaging_id:
|
||||
packaging_ids.append(supplier.packaging_id.id)
|
||||
|
||||
uom_id = new_uom_id if not qty else uom_id
|
||||
res = super(PurchaseOrderLine, self).onchange_product_id(
|
||||
cr, uid, ids, pricelist_id, product_id, qty, uom_id,
|
||||
partner_id, date_order=date_order,
|
||||
fiscal_position_id=fiscal_position_id, date_planned=date_planned,
|
||||
name=name, price_unit=price_unit, state=state, context=context)
|
||||
|
||||
if product_id and partner_id and not qty \
|
||||
and category_product_purchase_uom_id:
|
||||
res['value']['product_purchase_qty'] = product_purchase_qty
|
||||
res['value']['product_purchase_uom_id'] = product_purchase_uom_id
|
||||
uom_obj = self.pool['product.uom']
|
||||
to_uom_id = uom_obj.search(
|
||||
cr, uid,
|
||||
[('category_id', '=', category_product_purchase_uom_id),
|
||||
('uom_type', '=', 'reference')], limit=1, context=context)[0]
|
||||
res['value']['product_qty'] = uom_obj._compute_qty(
|
||||
cr, uid, product_purchase_uom_id,
|
||||
product_purchase_qty, to_uom_id)
|
||||
res['value']['packaging_id'] = packaging_id
|
||||
if domain:
|
||||
if res.get('domain'):
|
||||
res['domain'].update(domain)
|
||||
else:
|
||||
res['domain'] = domain
|
||||
return res
|
||||
|
||||
@api.model
|
||||
def update_vals(self, vals):
|
||||
"""
|
||||
When packaging_id is set, uom_id is readonly,
|
||||
so we need to reset the uom value in the vals dict
|
||||
"""
|
||||
if vals.get('packaging_id'):
|
||||
vals['product_uom'] = self.env['product.packaging'].browse(
|
||||
vals['packaging_id']).uom_id.id
|
||||
return vals
|
||||
|
||||
@api.model
|
||||
@api.returns('self', lambda rec: rec.id)
|
||||
def create(self, vals):
|
||||
if 'product_qty' not in vals and 'product_purchase_qty' in vals:
|
||||
# compute product_qty to avoid inverse computation and reset to 1
|
||||
uom_obj = self.env['product.uom']
|
||||
product_purchase_uom = uom_obj.browse(
|
||||
vals['product_purchase_uom_id'])
|
||||
to_uom = uom_obj.search(
|
||||
[('category_id', '=', product_purchase_uom.category_id.id),
|
||||
('uom_type', '=', 'reference')], limit=1)
|
||||
vals['product_qty'] = uom_obj._compute_qty(
|
||||
vals['product_purchase_uom_id'],
|
||||
vals['product_purchase_qty'],
|
||||
to_uom.id)
|
||||
return super(PurchaseOrderLine, self).create(self.update_vals(vals))
|
||||
|
||||
@api.multi
|
||||
def write(self, vals):
|
||||
return super(PurchaseOrderLine, self).write(self.update_vals(vals))
|
||||
|
||||
|
||||
class ProcurementOrder(models.Model):
|
||||
_inherit = 'procurement.order'
|
||||
|
||||
@api.model
|
||||
def _get_po_line_values_from_proc(self, procurement, partner, company,
|
||||
schedule_date):
|
||||
""" add packaging and update product_uom/quantity if necessary
|
||||
"""
|
||||
res = super(ProcurementOrder, self)._get_po_line_values_from_proc(
|
||||
procurement, partner, company, schedule_date)
|
||||
|
||||
uom_obj = self.env['product.uom']
|
||||
|
||||
for supplier in procurement.product_id.seller_ids:
|
||||
if (supplier.name.id == partner.id):
|
||||
if supplier.packaging_id:
|
||||
res['packaging_id'] = supplier.packaging_id.id
|
||||
new_uom_id = supplier.product_uom.id
|
||||
if new_uom_id != res['product_uom']:
|
||||
res['product_uom'] = new_uom_id
|
||||
qty = uom_obj._compute_qty(procurement.product_uom.id,
|
||||
procurement.product_qty,
|
||||
new_uom_id)
|
||||
res['product_qty'] = max(qty, supplier.qty)
|
||||
pricelist = partner.property_product_pricelist_purchase
|
||||
res['price_unit'] = pricelist.with_context(
|
||||
uom=new_uom_id).price_get(
|
||||
procurement.product_id.id, qty,
|
||||
partner=partner.id)[pricelist.id]
|
||||
break
|
||||
|
||||
return res
|
||||
179
purchase_packaging/models/purchase_order_line.py
Normal file
179
purchase_packaging/models/purchase_order_line.py
Normal file
@@ -0,0 +1,179 @@
|
||||
# -*- 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, fields, models
|
||||
import odoo.addons.decimal_precision as dp
|
||||
|
||||
|
||||
class PurchaseOrderLine(models.Model):
|
||||
_inherit = "purchase.order.line"
|
||||
|
||||
@api.model
|
||||
def _default_product_purchase_uom_id(self):
|
||||
return self.env.ref('product.product_uom_unit')
|
||||
|
||||
product_tmpl_id = fields.Many2one(
|
||||
related='product_id.product_tmpl_id',
|
||||
comodel_name='product.template'
|
||||
)
|
||||
packaging_id = fields.Many2one(
|
||||
'product.packaging',
|
||||
'Packaging'
|
||||
)
|
||||
product_purchase_qty = fields.Float(
|
||||
'Purchase quantity',
|
||||
digits=dp.get_precision('Product Unit of Measure'),
|
||||
required=True, default=lambda *a: 1.0
|
||||
)
|
||||
product_purchase_uom_id = fields.Many2one(
|
||||
'product.uom',
|
||||
'Purchase Unit of Measure',
|
||||
required=True,
|
||||
default=_default_product_purchase_uom_id
|
||||
)
|
||||
product_qty = fields.Float(
|
||||
compute="_compute_product_qty",
|
||||
string='Quantity',
|
||||
inverse='_inverse_product_qty'
|
||||
)
|
||||
|
||||
@api.multi
|
||||
def _get_product_seller(self):
|
||||
self.ensure_one()
|
||||
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],
|
||||
uom_id=self.product_uom)
|
||||
|
||||
@api.one
|
||||
@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)
|
||||
|
||||
@api.one
|
||||
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
|
||||
|
||||
@api.onchange("packaging_id")
|
||||
def _onchange_packaging_id(self):
|
||||
if self.packaging_id:
|
||||
self.product_uom = self.packaging_id.uom_id
|
||||
|
||||
@api.onchange('product_id')
|
||||
def onchange_product_id(self):
|
||||
""" set domain on product_purchase_uom_id and packaging_id
|
||||
set the first packagigng, purchase_uom and purchase_qty
|
||||
"""
|
||||
domain = {}
|
||||
# call default implementation
|
||||
# restore default values
|
||||
defaults = self.default_get(
|
||||
['packaging_id', 'product_purchase_uom_id'])
|
||||
self.packaging_id = self.packaging_id.browse(
|
||||
defaults.get('packaging_id', []))
|
||||
self.product_purchase_uom_id = self.product_purchase_uom_id.browse(
|
||||
defaults.get('product_purchase_uom_id', []))
|
||||
# add default domains
|
||||
if self.product_id and self.partner_id:
|
||||
domain['packaging_id'] = [
|
||||
('id', 'in', self.product_id.mapped(
|
||||
'seller_ids.packaging_id.id'))]
|
||||
domain['product_purchase_uom_id'] = \
|
||||
[('id', 'in', self.product_id.mapped(
|
||||
'seller_ids.min_qty_uom_id.id'))]
|
||||
res = super(PurchaseOrderLine, self).onchange_product_id()
|
||||
if self.product_id:
|
||||
supplier = self._get_product_seller()
|
||||
else:
|
||||
supplier = self.product_id.seller_ids.browse([])
|
||||
if supplier.product_uom:
|
||||
# use the uom from the suppleir
|
||||
self.product_uom = supplier.product_uom
|
||||
if supplier.min_qty_uom_id:
|
||||
# if the supplier requires some min qty/uom,
|
||||
self.product_purchase_qty = supplier.min_qty
|
||||
self.product_purchase_uom_id = supplier.min_qty_uom_id
|
||||
domain['product_purchase_uom_id'] = \
|
||||
[('id', '=', supplier.min_qty_uom_id.id)]
|
||||
to_uom = self.env['product.uom'].search([
|
||||
('category_id', '=',
|
||||
supplier.min_qty_uom_id.category_id.id),
|
||||
('uom_type', '=', 'reference')], limit=1)
|
||||
to_uom = to_uom and to_uom[0]
|
||||
self.product_qty = supplier.min_qty_uom_id._compute_quantity(
|
||||
supplier.min_qty, to_uom
|
||||
)
|
||||
self.packaging_id = supplier.packaging_id
|
||||
if domain:
|
||||
if res.get('domain'):
|
||||
res['domain'].update(domain)
|
||||
else:
|
||||
res['domain'] = domain
|
||||
return res
|
||||
|
||||
@api.multi
|
||||
def _prepare_stock_moves(self, picking):
|
||||
self.ensure_one()
|
||||
val = super(PurchaseOrderLine, self)._prepare_stock_moves(picking)
|
||||
for v in val:
|
||||
v['product_packaging'] = self.packaging_id.id
|
||||
return val
|
||||
|
||||
@api.model
|
||||
def update_vals(self, vals):
|
||||
"""
|
||||
When packaging_id is set, uom_id is readonly,
|
||||
so we need to reset the uom value in the vals dict
|
||||
"""
|
||||
if vals.get('packaging_id'):
|
||||
vals['product_uom'] = self.env['product.packaging'].browse(
|
||||
vals['packaging_id']).uom_id.id
|
||||
return vals
|
||||
|
||||
@api.model
|
||||
@api.returns('self', lambda rec: rec.id)
|
||||
def create(self, vals):
|
||||
if 'product_qty' not in vals and 'product_purchase_qty' in vals:
|
||||
# compute product_qty to avoid inverse computation and reset to 1
|
||||
uom_obj = self.env['product.uom']
|
||||
product_purchase_uom = uom_obj.browse(
|
||||
vals['product_purchase_uom_id'])
|
||||
to_uom = uom_obj.search(
|
||||
[('category_id', '=', product_purchase_uom.category_id.id),
|
||||
('uom_type', '=', 'reference')], limit=1)
|
||||
vals['product_qty'] = to_uom._compute_quantity(
|
||||
vals['product_purchase_qty'],
|
||||
to_uom)
|
||||
return super(PurchaseOrderLine, self).create(self.update_vals(vals))
|
||||
|
||||
@api.multi
|
||||
def write(self, vals):
|
||||
return super(PurchaseOrderLine, self).write(self.update_vals(vals))
|
||||
BIN
purchase_packaging/static/description/icon.png
Normal file
BIN
purchase_packaging/static/description/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 9.2 KiB |
@@ -1,3 +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 . import test_packaging
|
||||
from . import test_product_supplier_info
|
||||
from . import test_purchase_order_line
|
||||
from . import test_procurement_order
|
||||
|
||||
@@ -1,338 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# Authors: Laetitia Gangloff
|
||||
# Copyright (c) 2015 Acsone SA/NV (http://www.acsone.eu)
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
import openerp.tests.common as common
|
||||
|
||||
|
||||
class TestPackaging(common.TransactionCase):
|
||||
|
||||
def setUp(self):
|
||||
""" Create a packagings with uom product_uom_dozen on
|
||||
* product_product_34 (uom is product_uom_unit)
|
||||
"""
|
||||
super(TestPackaging, self).setUp()
|
||||
self.product_packaging_34 = self.env['product.packaging'].create(
|
||||
{'product_tmpl_id': self.env.ref('product.product_product_34'
|
||||
).product_tmpl_id.id,
|
||||
'uom_id': self.env.ref('product.product_uom_dozen').id})
|
||||
self.sp_30 = self.env.ref('product.product_supplierinfo_30')
|
||||
self.product_uom_8 = self.env['product.uom'].create(
|
||||
{'category_id': self.env.ref('product.product_uom_categ_unit').id,
|
||||
'name': 'COL8',
|
||||
'factor_inv': 8,
|
||||
'uom_type': 'bigger',
|
||||
'rounding': 1.0,
|
||||
})
|
||||
|
||||
def test_supplierinfo_product_uom(self):
|
||||
""" Check product_uom of product_supplierinfo_30 is product_uom_unit
|
||||
Set packaging_id product_packaging_34 on product_supplierinfo_30
|
||||
Check product_uom of product_supplierinfo_30 is product_uom_dozen
|
||||
"""
|
||||
self.assertEqual(self.sp_30.product_uom.id,
|
||||
self.env.ref('product.product_uom_unit').id)
|
||||
self.sp_30.packaging_id = self.product_packaging_34
|
||||
self.assertEqual(self.sp_30.product_uom.id,
|
||||
self.env.ref('product.product_uom_dozen').id)
|
||||
|
||||
def test_po_line(self):
|
||||
""" On supplierinfo set product_uom_8 as min_qty_uom_id
|
||||
On supplierinfo set 2 as min_qty
|
||||
Create purchase order line with product product_product_34
|
||||
Check packaging_id is product_packaging_34
|
||||
Check product_purchase_uom_id is product_uom_8
|
||||
Check product_purchase_qty is 2
|
||||
Check product_qty is 8*2 = 16
|
||||
Check price_unit is 12*38 = 456
|
||||
Check product_uom is product_uom_dozen
|
||||
Confirm po
|
||||
Check stock move packaging is product_packaging_34
|
||||
Check stock move product_uom is product_uom_dozen
|
||||
Check stock move product_qty is 16
|
||||
"""
|
||||
self.sp_30.min_qty_uom_id = self.product_uom_8
|
||||
self.sp_30.min_qty = 2
|
||||
self.sp_30.packaging_id = self.product_packaging_34
|
||||
|
||||
po = self.env['purchase.order'].create(
|
||||
{'partner_id': self.env.ref('base.res_partner_16').id,
|
||||
'location_id': self.env.ref('stock.stock_location_stock').id,
|
||||
'pricelist_id': self.env.ref('purchase.list0').id
|
||||
})
|
||||
|
||||
vals = self.env['purchase.order.line'].onchange_product_id(
|
||||
[],
|
||||
po.pricelist_id.id, self.env.ref('product.product_product_34').id,
|
||||
0, False, po.partner_id.id, date_order=po.date_order,
|
||||
fiscal_position_id=po.fiscal_position.id, date_planned=False,
|
||||
name=False, price_unit=False, state=po.state)
|
||||
vals['value']['order_id'] = po.id
|
||||
vals['value']['product_id'] = self.env.ref(
|
||||
'product.product_product_34').id
|
||||
po_line = self.env['purchase.order.line'].create(vals['value'])
|
||||
self.assertEqual(po_line.packaging_id.id,
|
||||
self.product_packaging_34.id)
|
||||
self.assertEqual(po_line.product_purchase_uom_id.id,
|
||||
self.product_uom_8.id)
|
||||
self.assertAlmostEqual(po_line.product_purchase_qty, 2)
|
||||
self.assertAlmostEqual(po_line.product_qty, 16)
|
||||
self.assertAlmostEqual(po_line.price_unit, 456)
|
||||
self.assertEqual(po_line.product_uom.id,
|
||||
self.env.ref('product.product_uom_dozen').id)
|
||||
po.signal_workflow('purchase_confirm')
|
||||
sm = po.picking_ids[0].move_lines[0]
|
||||
self.assertEqual(sm.product_packaging.id,
|
||||
self.product_packaging_34.id)
|
||||
self.assertEqual(sm.product_uom.id,
|
||||
self.env.ref('product.product_uom_dozen').id)
|
||||
self.assertAlmostEqual(sm.product_uom_qty, 16)
|
||||
|
||||
def test_procurement(self):
|
||||
""" On product set sale_price to 3
|
||||
On supplierinfo set min_qty as 0
|
||||
Create procurement line with rule buy and quantity 17
|
||||
run procurement
|
||||
Check product_purchase_uom_id is product_uom_unit
|
||||
Check product_purchase_qty is 17
|
||||
Check product_qty is 17
|
||||
Check packaging_id is False
|
||||
Check product_uom is product_uom_unit
|
||||
Check price_unit is 3
|
||||
Confirm Purchase Order to avoid group
|
||||
Create procurement line with rule buy and quantity 1 dozen
|
||||
run procurement
|
||||
Check product_purchase_uom_id is product_uom_unit
|
||||
Check product_purchase_qty is 12
|
||||
Check product_qty is 12
|
||||
Check packaging_id is False
|
||||
Check product_uom is product_uom_unit
|
||||
Check price_unit is 3
|
||||
Confirm Purchase Order to avoid group
|
||||
On supplierinfo set product_uom_8 as min_qty_uom_id
|
||||
Create procurement line with rule buy and quantity 17
|
||||
run procurement
|
||||
Check product_purchase_uom_id is product_uom_8
|
||||
Check product_purchase_qty is 3
|
||||
Check product_qty is 8*3 = 24
|
||||
Check packaging_id is False
|
||||
Check product_uom is product_uom_unit
|
||||
Check price_unit is 3
|
||||
Confirm Purchase Order to avoid group
|
||||
Create procurement line with rule buy and quantity 1 dozen
|
||||
run procurement
|
||||
Check product_purchase_uom_id is product_uom_8
|
||||
Check product_purchase_qty is 2
|
||||
Check product_qty is 8*2 = 16
|
||||
Check packaging_id is False
|
||||
Check product_uom is product_uom_unit
|
||||
Check price_unit is 3
|
||||
Confirm Purchase Order to avoid group
|
||||
On supplierinfo set packaging product_packaging_34 (dozen)
|
||||
Create procurement line with rule buy and quantity 17
|
||||
run procurement
|
||||
Check product_purchase_uom_id is product_uom_8
|
||||
Check product_purchase_qty is 1
|
||||
Check product_qty is 8*1 = 8
|
||||
Check packaging_id is product_packaging_34
|
||||
Check product_uom is product_uom_dozen
|
||||
Check price_unit is 3*12 = 36
|
||||
Confirm Purchase Order to avoid group
|
||||
Create procurement line with rule buy and quantity 1 dozen
|
||||
run procurement
|
||||
Check product_purchase_uom_id is product_uom_8
|
||||
Check product_purchase_qty is 1
|
||||
Check product_qty is 8*1 = 8
|
||||
Check packaging_id is product_packaging_34
|
||||
Check product_uom is product_uom_dozen
|
||||
Check price_unit is 3*12 = 36
|
||||
Confirm Purchase Order to avoid group
|
||||
On supplierinfo set product_uom_unit as min_qty_uom_id
|
||||
Create procurement line with rule buy and quantity 17
|
||||
run procurement
|
||||
Check product_purchase_uom_id is product_uom_unit
|
||||
Check product_purchase_qty is 2
|
||||
Check product_qty is 2
|
||||
Check packaging_id is product_packaging_34
|
||||
Check product_uom is product_uom_dozen
|
||||
Check price_unit is 3*12 = 36
|
||||
Confirm Purchase Order to avoid group
|
||||
Create procurement line with rule buy and quantity 1 dozen
|
||||
run procurement
|
||||
Check product_purchase_uom_id is product_uom_unit
|
||||
Check product_purchase_qty is 1
|
||||
Check product_qty is 1
|
||||
Check packaging_id is product_packaging_34
|
||||
Check product_uom is product_uom_dozen
|
||||
Check price_unit is 3*12 = 36
|
||||
Confirm Purchase Order to avoid group
|
||||
"""
|
||||
self.env.ref('product.product_product_34').route_ids = [(
|
||||
4, self.env.ref("purchase.route_warehouse0_buy").id)]
|
||||
self.env.ref('product.product_product_34').standard_price = 3
|
||||
self.env.ref('product.product_uom_unit').rounding = 1
|
||||
procurement_obj = self.env['procurement.order']
|
||||
|
||||
self.sp_30.min_qty = 0
|
||||
|
||||
proc1 = procurement_obj.create(
|
||||
{'name': 'test_procurement',
|
||||
'location_id': self.env.ref('stock.stock_location_stock').id,
|
||||
'product_id': self.env.ref('product.product_product_34').id,
|
||||
'product_qty': 17,
|
||||
'product_uom': self.env.ref('product.product_uom_unit').id})
|
||||
procurement_obj.run_scheduler()
|
||||
self.assertEqual(self.env.ref('product.product_uom_unit'),
|
||||
proc1.purchase_line_id.product_purchase_uom_id)
|
||||
self.assertEqual(17, proc1.purchase_line_id.product_purchase_qty)
|
||||
self.assertEqual(17, proc1.purchase_line_id.product_qty)
|
||||
self.assertFalse(proc1.purchase_line_id.packaging_id)
|
||||
self.assertEqual(self.env.ref('product.product_uom_unit'),
|
||||
proc1.purchase_line_id.product_uom)
|
||||
proc1.purchase_id.signal_workflow('purchase_confirm')
|
||||
|
||||
proc1 = procurement_obj.create(
|
||||
{'name': 'test_procurement',
|
||||
'location_id': self.env.ref('stock.stock_location_stock').id,
|
||||
'product_id': self.env.ref('product.product_product_34').id,
|
||||
'product_qty': 1,
|
||||
'product_uom': self.env.ref('product.product_uom_dozen').id})
|
||||
procurement_obj.run_scheduler()
|
||||
self.assertEqual(self.env.ref('product.product_uom_unit'),
|
||||
proc1.purchase_line_id.product_purchase_uom_id)
|
||||
self.assertEqual(12, proc1.purchase_line_id.product_purchase_qty)
|
||||
self.assertEqual(12, proc1.purchase_line_id.product_qty)
|
||||
self.assertFalse(proc1.purchase_line_id.packaging_id)
|
||||
self.assertEqual(self.env.ref('product.product_uom_unit'),
|
||||
proc1.purchase_line_id.product_uom)
|
||||
self.assertEqual(3, proc1.purchase_line_id.price_unit)
|
||||
proc1.purchase_id.signal_workflow('purchase_confirm')
|
||||
|
||||
self.sp_30.min_qty_uom_id = self.product_uom_8
|
||||
|
||||
proc1 = procurement_obj.create(
|
||||
{'name': 'test_procurement',
|
||||
'location_id': self.env.ref('stock.stock_location_stock').id,
|
||||
'product_id': self.env.ref('product.product_product_34').id,
|
||||
'product_qty': 17,
|
||||
'product_uom': self.env.ref('product.product_uom_unit').id})
|
||||
procurement_obj.run_scheduler()
|
||||
self.assertEqual(self.product_uom_8,
|
||||
proc1.purchase_line_id.product_purchase_uom_id)
|
||||
self.assertEqual(3, proc1.purchase_line_id.product_purchase_qty)
|
||||
self.assertEqual(24, proc1.purchase_line_id.product_qty)
|
||||
self.assertFalse(proc1.purchase_line_id.packaging_id)
|
||||
self.assertEqual(self.env.ref('product.product_uom_unit'),
|
||||
proc1.purchase_line_id.product_uom)
|
||||
self.assertEqual(3, proc1.purchase_line_id.price_unit)
|
||||
proc1.purchase_id.signal_workflow('purchase_confirm')
|
||||
|
||||
proc1 = procurement_obj.create(
|
||||
{'name': 'test_procurement',
|
||||
'location_id': self.env.ref('stock.stock_location_stock').id,
|
||||
'product_id': self.env.ref('product.product_product_34').id,
|
||||
'product_qty': 1,
|
||||
'product_uom': self.env.ref('product.product_uom_dozen').id})
|
||||
procurement_obj.run_scheduler()
|
||||
self.assertEqual(self.product_uom_8,
|
||||
proc1.purchase_line_id.product_purchase_uom_id)
|
||||
self.assertEqual(2, proc1.purchase_line_id.product_purchase_qty)
|
||||
self.assertEqual(16, proc1.purchase_line_id.product_qty)
|
||||
self.assertFalse(proc1.purchase_line_id.packaging_id)
|
||||
self.assertEqual(self.env.ref('product.product_uom_unit'),
|
||||
proc1.purchase_line_id.product_uom)
|
||||
self.assertEqual(3, proc1.purchase_line_id.price_unit)
|
||||
proc1.purchase_id.signal_workflow('purchase_confirm')
|
||||
|
||||
self.sp_30.packaging_id = self.product_packaging_34
|
||||
|
||||
proc1 = procurement_obj.create(
|
||||
{'name': 'test_procurement',
|
||||
'location_id': self.env.ref('stock.stock_location_stock').id,
|
||||
'product_id': self.env.ref('product.product_product_34').id,
|
||||
'product_qty': 17,
|
||||
'product_uom': self.env.ref('product.product_uom_unit').id})
|
||||
procurement_obj.run_scheduler()
|
||||
self.assertEqual(self.product_uom_8,
|
||||
proc1.purchase_line_id.product_purchase_uom_id)
|
||||
self.assertEqual(1, proc1.purchase_line_id.product_purchase_qty)
|
||||
self.assertEqual(8, proc1.purchase_line_id.product_qty)
|
||||
self.assertEqual(self.product_packaging_34,
|
||||
proc1.purchase_line_id.packaging_id)
|
||||
self.assertEqual(self.env.ref('product.product_uom_dozen'),
|
||||
proc1.purchase_line_id.product_uom)
|
||||
self.assertEqual(36, proc1.purchase_line_id.price_unit)
|
||||
proc1.purchase_id.signal_workflow('purchase_confirm')
|
||||
|
||||
proc1 = procurement_obj.create(
|
||||
{'name': 'test_procurement',
|
||||
'location_id': self.env.ref('stock.stock_location_stock').id,
|
||||
'product_id': self.env.ref('product.product_product_34').id,
|
||||
'product_qty': 1,
|
||||
'product_uom': self.env.ref('product.product_uom_dozen').id})
|
||||
procurement_obj.run_scheduler()
|
||||
self.assertEqual(self.product_uom_8,
|
||||
proc1.purchase_line_id.product_purchase_uom_id)
|
||||
self.assertEqual(1, proc1.purchase_line_id.product_purchase_qty)
|
||||
self.assertEqual(8, proc1.purchase_line_id.product_qty)
|
||||
self.assertEqual(self.product_packaging_34,
|
||||
proc1.purchase_line_id.packaging_id)
|
||||
self.assertEqual(self.env.ref('product.product_uom_dozen'),
|
||||
proc1.purchase_line_id.product_uom)
|
||||
self.assertEqual(36, proc1.purchase_line_id.price_unit)
|
||||
proc1.purchase_id.signal_workflow('purchase_confirm')
|
||||
|
||||
self.sp_30.min_qty_uom_id = self.env.ref('product.product_uom_unit')
|
||||
|
||||
proc1 = procurement_obj.create(
|
||||
{'name': 'test_procurement',
|
||||
'location_id': self.env.ref('stock.stock_location_stock').id,
|
||||
'product_id': self.env.ref('product.product_product_34').id,
|
||||
'product_qty': 17,
|
||||
'product_uom': self.env.ref('product.product_uom_unit').id})
|
||||
procurement_obj.run_scheduler()
|
||||
self.assertEqual(self.env.ref('product.product_uom_unit'),
|
||||
proc1.purchase_line_id.product_purchase_uom_id)
|
||||
self.assertEqual(2, proc1.purchase_line_id.product_purchase_qty)
|
||||
self.assertEqual(2, proc1.purchase_line_id.product_qty)
|
||||
self.assertEqual(self.product_packaging_34,
|
||||
proc1.purchase_line_id.packaging_id)
|
||||
self.assertEqual(self.env.ref('product.product_uom_dozen'),
|
||||
proc1.purchase_line_id.product_uom)
|
||||
self.assertEqual(36, proc1.purchase_line_id.price_unit)
|
||||
proc1.purchase_id.signal_workflow('purchase_confirm')
|
||||
|
||||
proc1 = procurement_obj.create(
|
||||
{'name': 'test_procurement',
|
||||
'location_id': self.env.ref('stock.stock_location_stock').id,
|
||||
'product_id': self.env.ref('product.product_product_34').id,
|
||||
'product_qty': 1,
|
||||
'product_uom': self.env.ref('product.product_uom_dozen').id})
|
||||
procurement_obj.run_scheduler()
|
||||
self.assertEqual(self.env.ref('product.product_uom_unit'),
|
||||
proc1.purchase_line_id.product_purchase_uom_id)
|
||||
self.assertEqual(1, proc1.purchase_line_id.product_purchase_qty)
|
||||
self.assertEqual(1, proc1.purchase_line_id.product_qty)
|
||||
self.assertEqual(self.product_packaging_34,
|
||||
proc1.purchase_line_id.packaging_id)
|
||||
self.assertEqual(self.env.ref('product.product_uom_dozen'),
|
||||
proc1.purchase_line_id.product_uom)
|
||||
self.assertEqual(36, proc1.purchase_line_id.price_unit)
|
||||
proc1.purchase_id.signal_workflow('purchase_confirm')
|
||||
261
purchase_packaging/tests/test_procurement_order.py
Normal file
261
purchase_packaging/tests/test_procurement_order.py
Normal file
@@ -0,0 +1,261 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2015-2017 ACSONE SA/NV (<http://acsone.eu>)
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
import odoo.tests.common as common
|
||||
|
||||
|
||||
class TestProcurementOrder(common.TransactionCase):
|
||||
|
||||
def setUp(self):
|
||||
""" Create a packagings with uom product_uom_dozen on
|
||||
* product_product_3 (uom is product_uom_unit)
|
||||
"""
|
||||
super(TestProcurementOrder, self).setUp()
|
||||
self.product_packaging_3 = self.env['product.packaging'].create(
|
||||
{'product_tmpl_id': self.env.ref('product.product_product_3'
|
||||
).product_tmpl_id.id,
|
||||
'uom_id': self.env.ref('product.product_uom_dozen').id,
|
||||
'name': 'Packaging Dozen'})
|
||||
self.sp_30 = self.env.ref('product.product_supplierinfo_1')
|
||||
self.sp_30.product_tmpl_id = self.product_packaging_3.product_tmpl_id
|
||||
self.sp_30.currency_id = self.env.user.company_id.currency_id
|
||||
self.product_uom_8 = self.env['product.uom'].create(
|
||||
{'category_id': self.env.ref('product.product_uom_categ_unit').id,
|
||||
'name': 'COL8',
|
||||
'factor_inv': 8,
|
||||
'uom_type': 'bigger',
|
||||
'rounding': 1.0,
|
||||
})
|
||||
self.env['purchase.order'].search(
|
||||
[("state", "=", "draft")]).button_cancel()
|
||||
|
||||
def test_procurement(self):
|
||||
# On supplierinfo set price to 3
|
||||
# On supplierinfo set min_qty as 0
|
||||
# Create procurement line with rule buy and quantity 17
|
||||
# run procurement
|
||||
self.env.ref('product.product_product_3').route_ids = [(
|
||||
4, self.env.ref("purchase.route_warehouse0_buy").id)]
|
||||
self.env.ref('product.product_uom_unit').rounding = 1
|
||||
procurement_obj = self.env['procurement.order']
|
||||
|
||||
self.sp_30.min_qty = 0
|
||||
self.sp_30.price = 3
|
||||
|
||||
proc1 = procurement_obj.create(
|
||||
{'name': 'test_procurement',
|
||||
'location_id': self.env.ref('stock.stock_location_stock').id,
|
||||
'product_id': self.env.ref('product.product_product_3').id,
|
||||
'product_qty': 17,
|
||||
'product_uom': self.env.ref('product.product_uom_unit').id})
|
||||
procurement_obj.run_scheduler()
|
||||
# Check product_purchase_uom_id is product_uom_unit
|
||||
# Check product_purchase_qty is 17
|
||||
# Check product_qty is 17
|
||||
# Check packaging_id is False
|
||||
# Check product_uom is product_uom_unit
|
||||
# Check price_unit is 3
|
||||
self.assertEqual(self.env.ref('product.product_uom_unit'),
|
||||
proc1.purchase_line_id.product_purchase_uom_id)
|
||||
self.assertEqual(17, proc1.purchase_line_id.product_purchase_qty)
|
||||
self.assertEqual(17, proc1.purchase_line_id.product_qty)
|
||||
self.assertFalse(proc1.purchase_line_id.packaging_id)
|
||||
self.assertEqual(self.env.ref('product.product_uom_unit'),
|
||||
proc1.purchase_line_id.product_uom)
|
||||
self.assertEqual(3, proc1.purchase_line_id.price_unit)
|
||||
# Confirm Purchase Order to avoid group
|
||||
proc1.purchase_id.button_confirm()
|
||||
|
||||
# Create procurement line with rule buy and quantity 1 dozen
|
||||
# run procurement
|
||||
proc1 = procurement_obj.create(
|
||||
{'name': 'test_procurement',
|
||||
'location_id': self.env.ref('stock.stock_location_stock').id,
|
||||
'product_id': self.env.ref('product.product_product_3').id,
|
||||
'product_qty': 1,
|
||||
'product_uom': self.env.ref('product.product_uom_dozen').id})
|
||||
procurement_obj.run_scheduler()
|
||||
# Check product_purchase_uom_id is product_uom_unit
|
||||
# Check product_purchase_qty is 12
|
||||
# Check product_qty is 12
|
||||
# Check packaging_id is False
|
||||
# Check product_uom is product_uom_unit
|
||||
# Check price_unit is 3
|
||||
self.assertEqual(self.env.ref('product.product_uom_unit'),
|
||||
proc1.purchase_line_id.product_purchase_uom_id)
|
||||
self.assertEqual(12, proc1.purchase_line_id.product_purchase_qty)
|
||||
self.assertEqual(12, proc1.purchase_line_id.product_qty)
|
||||
self.assertFalse(proc1.purchase_line_id.packaging_id)
|
||||
self.assertEqual(self.env.ref('product.product_uom_unit'),
|
||||
proc1.purchase_line_id.product_uom)
|
||||
self.assertEqual(3, proc1.purchase_line_id.price_unit)
|
||||
# Confirm Purchase Order to avoid group
|
||||
proc1.purchase_id.button_confirm()
|
||||
|
||||
# On supplierinfo set product_uom_8 as min_qty_uom_id
|
||||
# Create procurement line with rule buy and quantity 17
|
||||
# run procurement
|
||||
self.sp_30.min_qty_uom_id = self.product_uom_8
|
||||
|
||||
proc1 = procurement_obj.create(
|
||||
{'name': 'test_procurement',
|
||||
'location_id': self.env.ref('stock.stock_location_stock').id,
|
||||
'product_id': self.env.ref('product.product_product_3').id,
|
||||
'product_qty': 17,
|
||||
'product_uom': self.env.ref('product.product_uom_unit').id})
|
||||
procurement_obj.run_scheduler()
|
||||
# Check product_purchase_uom_id is product_uom_8
|
||||
# Check product_purchase_qty is 3
|
||||
# Check product_qty is 8*3 = 24
|
||||
# Check packaging_id is False
|
||||
# Check product_uom is product_uom_unit
|
||||
# Check price_unit is 3
|
||||
self.assertEqual(self.product_uom_8,
|
||||
proc1.purchase_line_id.product_purchase_uom_id)
|
||||
self.assertEqual(3, proc1.purchase_line_id.product_purchase_qty)
|
||||
self.assertEqual(24, proc1.purchase_line_id.product_qty)
|
||||
self.assertFalse(proc1.purchase_line_id.packaging_id)
|
||||
self.assertEqual(self.env.ref('product.product_uom_unit'),
|
||||
proc1.purchase_line_id.product_uom)
|
||||
self.assertEqual(3, proc1.purchase_line_id.price_unit)
|
||||
# Confirm Purchase Order to avoid group
|
||||
proc1.purchase_id.button_confirm()
|
||||
|
||||
# Create procurement line with rule buy and quantity 1 dozen
|
||||
# run procurement
|
||||
proc1 = procurement_obj.create(
|
||||
{'name': 'test_procurement',
|
||||
'location_id': self.env.ref('stock.stock_location_stock').id,
|
||||
'product_id': self.env.ref('product.product_product_3').id,
|
||||
'product_qty': 1,
|
||||
'product_uom': self.env.ref('product.product_uom_dozen').id})
|
||||
procurement_obj.run_scheduler()
|
||||
# Check product_purchase_uom_id is product_uom_8
|
||||
# Check product_purchase_qty is 2
|
||||
# Check product_qty is 8*2 = 16
|
||||
# Check packaging_id is False
|
||||
# Check product_uom is product_uom_unit
|
||||
# Check price_unit is 3
|
||||
self.assertEqual(self.product_uom_8,
|
||||
proc1.purchase_line_id.product_purchase_uom_id)
|
||||
self.assertEqual(2, proc1.purchase_line_id.product_purchase_qty)
|
||||
self.assertEqual(16, proc1.purchase_line_id.product_qty)
|
||||
self.assertFalse(proc1.purchase_line_id.packaging_id)
|
||||
self.assertEqual(self.env.ref('product.product_uom_unit'),
|
||||
proc1.purchase_line_id.product_uom)
|
||||
self.assertEqual(3, proc1.purchase_line_id.price_unit)
|
||||
# Confirm Purchase Order to avoid group
|
||||
proc1.purchase_id.button_confirm()
|
||||
|
||||
# On supplierinfo set packaging product_packaging_3 (dozen)
|
||||
# Create procurement line with rule buy and quantity 17
|
||||
# run procurement
|
||||
self.sp_30.packaging_id = self.product_packaging_3
|
||||
|
||||
proc1 = procurement_obj.create(
|
||||
{'name': 'test_procurement',
|
||||
'location_id': self.env.ref('stock.stock_location_stock').id,
|
||||
'product_id': self.env.ref('product.product_product_3').id,
|
||||
'product_qty': 17,
|
||||
'product_uom': self.env.ref('product.product_uom_unit').id})
|
||||
procurement_obj.run_scheduler()
|
||||
# Check product_purchase_uom_id is product_uom_8
|
||||
# Check product_purchase_qty is 1
|
||||
# Check product_qty is 8*1 = 8
|
||||
# Check packaging_id is product_packaging_3
|
||||
# Check product_uom is product_uom_dozen
|
||||
# Check price_unit is 3*12 = 36
|
||||
self.assertEqual(self.product_uom_8,
|
||||
proc1.purchase_line_id.product_purchase_uom_id)
|
||||
self.assertEqual(1, proc1.purchase_line_id.product_purchase_qty)
|
||||
self.assertEqual(8, proc1.purchase_line_id.product_qty)
|
||||
self.assertEqual(self.product_packaging_3,
|
||||
proc1.purchase_line_id.packaging_id)
|
||||
self.assertEqual(self.env.ref('product.product_uom_dozen'),
|
||||
proc1.purchase_line_id.product_uom)
|
||||
self.assertEqual(3, proc1.purchase_line_id.price_unit)
|
||||
# Confirm Purchase Order to avoid group
|
||||
proc1.purchase_id.button_confirm()
|
||||
|
||||
# Create procurement line with rule buy and quantity 1 dozen
|
||||
# run procurement
|
||||
proc1 = procurement_obj.create(
|
||||
{'name': 'test_procurement',
|
||||
'location_id': self.env.ref('stock.stock_location_stock').id,
|
||||
'product_id': self.env.ref('product.product_product_3').id,
|
||||
'product_qty': 1,
|
||||
'product_uom': self.env.ref('product.product_uom_dozen').id})
|
||||
procurement_obj.run_scheduler()
|
||||
# Check product_purchase_uom_id is product_uom_8
|
||||
# Check product_purchase_qty is 1
|
||||
# Check product_qty is 8*1 = 8
|
||||
# Check packaging_id is product_packaging_3
|
||||
# Check product_uom is product_uom_dozen
|
||||
self.assertEqual(self.product_uom_8,
|
||||
proc1.purchase_line_id.product_purchase_uom_id)
|
||||
self.assertEqual(1, proc1.purchase_line_id.product_purchase_qty)
|
||||
self.assertEqual(8, proc1.purchase_line_id.product_qty)
|
||||
self.assertEqual(self.product_packaging_3,
|
||||
proc1.purchase_line_id.packaging_id)
|
||||
self.assertEqual(self.env.ref('product.product_uom_dozen'),
|
||||
proc1.purchase_line_id.product_uom)
|
||||
self.assertEqual(3, proc1.purchase_line_id.price_unit)
|
||||
# Confirm Purchase Order to avoid group
|
||||
proc1.purchase_id.button_confirm()
|
||||
|
||||
# On supplierinfo set product_uom_unit as min_qty_uom_id
|
||||
# Create procurement line with rule buy and quantity 17
|
||||
# run procurement
|
||||
self.sp_30.min_qty_uom_id = self.env.ref('product.product_uom_unit')
|
||||
|
||||
proc1 = procurement_obj.create(
|
||||
{'name': 'test_procurement',
|
||||
'location_id': self.env.ref('stock.stock_location_stock').id,
|
||||
'product_id': self.env.ref('product.product_product_3').id,
|
||||
'product_qty': 17,
|
||||
'product_uom': self.env.ref('product.product_uom_unit').id})
|
||||
procurement_obj.run_scheduler()
|
||||
# Check product_purchase_uom_id is product_uom_unit
|
||||
# Check product_purchase_qty is 2
|
||||
# Check product_qty is 2
|
||||
# Check packaging_id is product_packaging_3
|
||||
# Check product_uom is product_uom_dozen
|
||||
self.assertEqual(self.env.ref('product.product_uom_unit'),
|
||||
proc1.purchase_line_id.product_purchase_uom_id)
|
||||
self.assertEqual(2, proc1.purchase_line_id.product_purchase_qty)
|
||||
self.assertEqual(2, proc1.purchase_line_id.product_qty)
|
||||
self.assertEqual(self.product_packaging_3,
|
||||
proc1.purchase_line_id.packaging_id)
|
||||
self.assertEqual(self.env.ref('product.product_uom_dozen'),
|
||||
proc1.purchase_line_id.product_uom)
|
||||
self.assertEqual(3, proc1.purchase_line_id.price_unit)
|
||||
# Confirm Purchase Order to avoid group
|
||||
proc1.purchase_id.button_confirm()
|
||||
|
||||
# Create procurement line with rule buy and quantity 1 dozen
|
||||
# set purcahse price to 36
|
||||
# run procurement
|
||||
self.sp_30.price = 36
|
||||
proc1 = procurement_obj.create(
|
||||
{'name': 'test_procurement',
|
||||
'location_id': self.env.ref('stock.stock_location_stock').id,
|
||||
'product_id': self.env.ref('product.product_product_3').id,
|
||||
'product_qty': 1,
|
||||
'product_uom': self.env.ref('product.product_uom_dozen').id})
|
||||
procurement_obj.run_scheduler()
|
||||
# Check product_purchase_uom_id is product_uom_unit
|
||||
# Check product_purchase_qty is 1
|
||||
# Check product_qty is 1
|
||||
# Check packaging_id is product_packaging_3
|
||||
# Check product_uom is product_uom_dozen
|
||||
# Check price_unit is 3*12 = 36
|
||||
self.assertEqual(self.env.ref('product.product_uom_unit'),
|
||||
proc1.purchase_line_id.product_purchase_uom_id)
|
||||
self.assertEqual(1, proc1.purchase_line_id.product_purchase_qty)
|
||||
self.assertEqual(1, proc1.purchase_line_id.product_qty)
|
||||
self.assertEqual(self.product_packaging_3,
|
||||
proc1.purchase_line_id.packaging_id)
|
||||
self.assertEqual(self.env.ref('product.product_uom_dozen'),
|
||||
proc1.purchase_line_id.product_uom)
|
||||
self.assertEqual(36, proc1.purchase_line_id.price_unit)
|
||||
proc1.purchase_id.button_confirm()
|
||||
35
purchase_packaging/tests/test_product_supplier_info.py
Normal file
35
purchase_packaging/tests/test_product_supplier_info.py
Normal file
@@ -0,0 +1,35 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2015-2017 ACSONE SA/NV (<http://acsone.eu>)
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
import odoo.tests.common as common
|
||||
|
||||
|
||||
class TestProductSupplierInfo(common.TransactionCase):
|
||||
|
||||
def setUp(self):
|
||||
""" Create a packagings with uom product_uom_dozen on
|
||||
product_supplierinfo_1'product (uom is product_uom_unit)
|
||||
"""
|
||||
super(TestProductSupplierInfo, self).setUp()
|
||||
self.product_supplier_info = self.env.ref(
|
||||
'product.product_supplierinfo_1')
|
||||
self.product_tmpl_id = self.product_supplier_info.product_tmpl_id
|
||||
self.product_supplier_info.product_tmpl_id.uom_po_id = self.env.ref(
|
||||
'product.product_uom_unit')
|
||||
self.product_packaging_dozen = self.env['product.packaging'].create(
|
||||
{'product_tmpl_id': self.product_tmpl_id.id,
|
||||
'uom_id': self.env.ref('product.product_uom_dozen').id,
|
||||
'name': 'Packaging Dozen'}
|
||||
)
|
||||
|
||||
def test_supplierinfo_product_uom(self):
|
||||
""" Check product_uom of product_supplierinfo_30 is product_uom_unit
|
||||
Set packaging_id product_packaging_3 on product_supplierinfo_30
|
||||
Check product_uom of product_supplierinfo_30 is product_uom_dozen
|
||||
"""
|
||||
self.assertEqual(self.product_supplier_info.product_uom.id,
|
||||
self.env.ref('product.product_uom_unit').id)
|
||||
self.product_supplier_info.write(
|
||||
{'packaging_id': self.product_packaging_dozen.id})
|
||||
self.assertEqual(self.product_supplier_info.product_uom.id,
|
||||
self.env.ref('product.product_uom_dozen').id)
|
||||
81
purchase_packaging/tests/test_purchase_order_line.py
Normal file
81
purchase_packaging/tests/test_purchase_order_line.py
Normal file
@@ -0,0 +1,81 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2015-2017 ACSONE SA/NV (<http://acsone.eu>)
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
import odoo.tests.common as common
|
||||
|
||||
|
||||
class TestPurchaseOrderLine(common.TransactionCase):
|
||||
|
||||
def setUp(self):
|
||||
""" Create a packagings with uom product_uom_dozen on
|
||||
product_supplierinfo_1'product (uom is product_uom_unit)
|
||||
"""
|
||||
super(TestPurchaseOrderLine, self).setUp()
|
||||
self.product_supplier_info = self.env.ref(
|
||||
'product.product_supplierinfo_1')
|
||||
self.product_tmpl_id = self.product_supplier_info.product_tmpl_id
|
||||
self.product_supplier_info.product_tmpl_id.uom_po_id = self.env.ref(
|
||||
'product.product_uom_unit')
|
||||
self.product_supplier_info.min_qty = 1
|
||||
self.product_packaging_dozen = self.env['product.packaging'].create(
|
||||
{'product_tmpl_id': self.product_tmpl_id.id,
|
||||
'uom_id': self.env.ref('product.product_uom_dozen').id,
|
||||
'name': 'Packaging Dozen'}
|
||||
)
|
||||
self.product_uom_8 = self.env['product.uom'].create(
|
||||
{'category_id': self.env.ref('product.product_uom_categ_unit').id,
|
||||
'name': 'COL8',
|
||||
'factor_inv': 8,
|
||||
'uom_type': 'bigger',
|
||||
'rounding': 1.0,
|
||||
})
|
||||
|
||||
def test_po_line(self):
|
||||
""" On supplierinfo set product_uom_8 as min_qty_uom_id
|
||||
On supplierinfo set 2 as min_qty
|
||||
Create purchase order line with product product_product_3
|
||||
Check packaging_id is product_packaging_dozen
|
||||
Check product_purchase_uom_id is product_uom_8
|
||||
Check product_purchase_qty is 2
|
||||
Check product_qty is 8*2 = 16
|
||||
Check price_unit is 12*38 = 456
|
||||
Check product_uom is product_uom_dozen
|
||||
Confirm po
|
||||
Check stock move packaging is product_packaging_dozen
|
||||
Check stock move product_uom is product_uom_dozen
|
||||
Check stock move product_qty is 16
|
||||
"""
|
||||
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.assertEqual(po_line.packaging_id.id,
|
||||
self.product_packaging_dozen.id)
|
||||
self.assertEqual(po_line.product_purchase_uom_id.id,
|
||||
self.product_uom_8.id)
|
||||
self.assertAlmostEqual(po_line.product_purchase_qty, 2)
|
||||
self.assertAlmostEqual(po_line.product_qty, 16)
|
||||
self.assertTrue(po_line.price_unit)
|
||||
self.assertEqual(po_line.product_uom.id,
|
||||
self.env.ref('product.product_uom_dozen').id)
|
||||
values = po_line._convert_to_write(
|
||||
{name: po_line[name] for name in po_line._cache})
|
||||
po.order_line.create(values)
|
||||
# check that all the packaging informations are on the created picking
|
||||
po._create_picking()
|
||||
sm = po.picking_ids[0].move_lines[0]
|
||||
self.assertEqual(sm.product_packaging.id,
|
||||
self.product_packaging_dozen.id)
|
||||
self.assertEqual(sm.product_uom.id,
|
||||
self.env.ref('product.product_uom_dozen').id)
|
||||
self.assertAlmostEqual(sm.product_uom_qty, 16)
|
||||
@@ -1,4 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright 2015-2017 ACSONE SA/NV (<http://acsone.eu>)
|
||||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
|
||||
<openerp>
|
||||
<data>
|
||||
|
||||
26
purchase_packaging/views/purchase_order_line_view.xml
Normal file
26
purchase_packaging/views/purchase_order_line_view.xml
Normal file
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright 2015-2017 ACSONE SA/NV (<http://acsone.eu>)
|
||||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
|
||||
<odoo>
|
||||
<record id="purchase_order_line_view_form_inherit_purchase_packaging" model="ir.ui.view">
|
||||
<field name="name">purchase.order.line.form (purchase_packaging)</field>
|
||||
<field name="model">purchase.order.line</field>
|
||||
<field name="inherit_id" ref="purchase.purchase_order_line_form2"/>
|
||||
<field name="arch" type="xml">
|
||||
<data>
|
||||
<field name="product_qty" position="attributes">
|
||||
<attribute name="readonly">1</attribute>
|
||||
</field>
|
||||
<label for="product_qty" position="before">
|
||||
<field name="product_tmpl_id" invisible="1"/>
|
||||
<field name="packaging_id" domain="[('product_tmpl_id','=',product_tmpl_id)]" groups="product.group_stock_packaging"/>
|
||||
<field name="product_purchase_qty"/>
|
||||
<field name="product_purchase_uom_id" groups="product.group_uom"/>
|
||||
</label>
|
||||
<field name="product_uom" position="attributes">
|
||||
<attribute name="attrs">{'readonly' : [('packaging_id', '!=', False)]}</attribute>
|
||||
</field>
|
||||
</data>
|
||||
</field>
|
||||
</record>
|
||||
</odoo>
|
||||
44
purchase_packaging/views/purchase_order_view.xml
Normal file
44
purchase_packaging/views/purchase_order_view.xml
Normal file
@@ -0,0 +1,44 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright 2015-2017 ACSONE SA/NV (<http://acsone.eu>)
|
||||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
|
||||
<odoo>
|
||||
<record id="purchase_order_view_form_inherit_purchase_packaging" model="ir.ui.view">
|
||||
<field name="name">purchase.order.form (purchase_packaging)</field>
|
||||
<field name="model">purchase.order</field>
|
||||
<field name="inherit_id" ref="purchase.purchase_order_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<data>
|
||||
<!-- order_line tree -->
|
||||
<xpath expr="//page//field[@name='order_line']/tree/field[@name='product_id']" position="after">
|
||||
<field name="product_tmpl_id" invisible="1"/>
|
||||
<field name="packaging_id" domain="[('product_tmpl_id','=',product_tmpl_id)]" groups="product.group_stock_packaging"/>
|
||||
</xpath>
|
||||
<xpath expr="//page/field[@name='order_line']/tree/field[@name='product_qty']" position="attributes">
|
||||
<attribute name="readonly">1</attribute>
|
||||
</xpath>
|
||||
<xpath expr="//page//field[@name='order_line']/tree/field[@name='product_qty']" position="before">
|
||||
<field name="product_purchase_qty"/>
|
||||
<field name="product_purchase_uom_id" groups="product.group_uom"/>
|
||||
</xpath>
|
||||
<xpath expr="//page//field[@name='order_line']/tree/field[@name='product_uom']" position="attributes">
|
||||
<attribute name="attrs">{'readonly' : [('packaging_id', '!=', False)]}</attribute>
|
||||
</xpath>
|
||||
<!-- order_line form -->
|
||||
<xpath expr="//page//field[@name='order_line']/form//field[@name='product_id']" position="after">
|
||||
<field name="product_tmpl_id" invisible="1"/>
|
||||
<field name="packaging_id" domain="[('product_tmpl_id','=',product_tmpl_id)]" groups="product.group_stock_packaging"/>
|
||||
</xpath>
|
||||
<xpath expr="//page/field[@name='order_line']/form//field[@name='product_qty']" position="attributes">
|
||||
<attribute name="readonly">1</attribute>
|
||||
</xpath>
|
||||
<xpath expr="//page//field[@name='order_line']/form//field[@name='product_qty']" position="before">
|
||||
<field name="product_purchase_qty"/>
|
||||
<field name="product_purchase_uom_id" groups="product.group_uom"/>
|
||||
</xpath>
|
||||
<xpath expr="//page//field[@name='order_line']/form//field[@name='product_uom']" position="attributes">
|
||||
<attribute name="attrs">{'readonly' : [('packaging_id', '!=', False)]}</attribute>
|
||||
</xpath>
|
||||
</data>
|
||||
</field>
|
||||
</record>
|
||||
</odoo>
|
||||
@@ -1,52 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<openerp>
|
||||
<data>
|
||||
|
||||
<record id="purchase_order_view_form_inherit_purchase_packaging" model="ir.ui.view">
|
||||
<field name="name">purchase.order.form (purchase_packaging)</field>
|
||||
<field name="model">purchase.order</field>
|
||||
<field name="inherit_id" ref="purchase.purchase_order_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<data>
|
||||
<xpath expr="//page[@string='Products']//field[@name='order_line']/tree[@string='Purchase Order Lines']/field[@name='product_id']" position="after">
|
||||
<field name="product_tmpl_id" invisible="1"/>
|
||||
<field name="packaging_id" domain="[('product_tmpl_id','=',product_tmpl_id)]" groups="product.group_stock_packaging"/>
|
||||
</xpath>
|
||||
<xpath expr="//page[@string='Products']//field[@name='order_line']/tree[@string='Purchase Order Lines']/field[@name='product_qty']" position="attributes">
|
||||
<attribute name="readonly">1</attribute>
|
||||
</xpath>
|
||||
<xpath expr="//page[@string='Products']//field[@name='order_line']/tree[@string='Purchase Order Lines']/field[@name='product_qty']" position="before">
|
||||
<field name="product_purchase_qty"/>
|
||||
<field name="product_purchase_uom_id" groups="product.group_uom"/>
|
||||
</xpath>
|
||||
<xpath expr="//page[@string='Products']//field[@name='order_line']/tree[@string='Purchase Order Lines']/field[@name='product_uom']" position="attributes">
|
||||
<attribute name="attrs">{'readonly' : [('packaging_id', '!=', False)]}</attribute>
|
||||
</xpath>
|
||||
</data>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="purchase_order_line_view_form_inherit_purchase_packaging" model="ir.ui.view">
|
||||
<field name="name">purchase.order.line.form (purchase_packaging)</field>
|
||||
<field name="model">purchase.order.line</field>
|
||||
<field name="inherit_id" ref="purchase.purchase_order_line_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<data>
|
||||
<field name="product_qty" position="attributes">
|
||||
<attribute name="readonly">1</attribute>
|
||||
</field>
|
||||
<label for="product_qty" position="before">
|
||||
<field name="product_tmpl_id" invisible="1"/>
|
||||
<field name="packaging_id" domain="[('product_tmpl_id','=',product_tmpl_id)]" groups="product.group_stock_packaging"/>
|
||||
<field name="product_purchase_qty"/>
|
||||
<field name="product_purchase_uom_id" groups="product.group_uom"/>
|
||||
</label>
|
||||
<field name="product_uom" position="attributes">
|
||||
<attribute name="attrs">{'readonly' : [('packaging_id', '!=', False)]}</attribute>
|
||||
</field>
|
||||
</data>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
Reference in New Issue
Block a user