Skip to content

Commit

Permalink
[IMP] product_packaging_through_attributes: updated code to OCA standard
Browse files Browse the repository at this point in the history
* sale_packaging_info: required changes and OCA standard adapt
* purchase_packaging_info: required changes and OCA standard adapt
  • Loading branch information
oihane committed Aug 1, 2016
1 parent b140136 commit 4b25c02
Show file tree
Hide file tree
Showing 16 changed files with 189 additions and 111 deletions.
1 change: 1 addition & 0 deletions product_packaging_through_attributes/README.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
====================================
Product Packaging through Attributes
====================================

Expand Down
7 changes: 3 additions & 4 deletions product_packaging_through_attributes/__openerp__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@

{
"name": "Product Packaging through Attributes",
"version": "1.0",
"version": "8.0.1.1.0",
"depends": [
"base",
"product",
"product_packaging_views",
"product_attribute_types",
],
"author": "OdooMRP team,"
"AvanzOSC,"
"author": "OdooMRP team, "
"AvanzOSC, "
"Serv. Tecnol. Avanzados - Pedro M. Baeza",
"website": "http://www.odoomrp.com",
"contributors": [
Expand All @@ -35,7 +35,6 @@
"Ana Juaristi <[email protected]>"
],
"category": "Custom Module",
"summary": "",
"data": [
"views/product_view.xml",
"views/res_partner_view.xml",
Expand Down
6 changes: 3 additions & 3 deletions product_packaging_through_attributes/i18n/es.po
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ msgid "Is package"
msgstr "Es envase"

#. module: product_packaging_through_attributes
#: field:res.partner,partner_product_ul:0
#: field:res.partner,partner_product_ul_id:0
msgid "Logistic Unit"
msgstr "Unidad logística"

#. module: product_packaging_through_attributes
#: field:product.attribute.value,package_product:0
#: field:product.packaging,product:0
#: field:product.attribute.value,package_product_id:0
#: field:product.packaging,product_id:0
msgid "Package Product"
msgstr "Producto envase"

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# -*- coding: utf-8 -*-
# © 2016 Oihane Crucelaegui - AvanzOSC
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html


def update_columns(cr):
cr.execute(
"""
ALTER TABLE product_attribute_value
RENAME COLUMN package_product TO package_product_id
""")
cr.execute(
"""
ALTER TABLE product_packaging
RENAME COLUMN product TO product_id
""")
cr.execute(
"""
ALTER TABLE res_partner
RENAME COLUMN partner_product_ul TO partner_product_ul_id
""")


def migrate(cr, version):
if not version:
return
update_columns(cr)
10 changes: 5 additions & 5 deletions product_packaging_through_attributes/models/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ class ProductAttributeValue(models.Model):

is_package_attr = fields.Boolean(
string='Package attribute', related='attribute_id.is_package')
package_product = fields.Many2one(
package_product_id = fields.Many2one(
comodel_name='product.product', string='Package Product',
context="{'default_sale_ok': False, 'default_purchase_ok': False}")


class ProductPackaging(models.Model):
_inherit = 'product.packaging'

product = fields.Many2one(
product_id = fields.Many2one(
comodel_name='product.product', string='Package Product',
context="{'default_sale_ok': False, 'default_purchase_ok': False}")

@api.one
@api.onchange('product')
@api.multi
@api.onchange('product_id')
def onchange_product(self):
self.product_tmpl_id = self.product.product_tmpl_id
self.product_tmpl_id = self.product_id.product_tmpl_id
2 changes: 1 addition & 1 deletion product_packaging_through_attributes/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
class ResPartner(models.Model):
_inherit = 'res.partner'

partner_product_ul = fields.Many2one(
partner_product_ul_id = fields.Many2one(
comodel_name='product.ul', string='Logistic Unit')
8 changes: 4 additions & 4 deletions product_packaging_through_attributes/views/product_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
ref="product_attribute_types.product_attribute_value_extended_tree_view" />
<field name="arch" type="xml">
<field name="numeric_value" position="after">
<field name="package_product"
<field name="package_product_id"
attrs="{'required':[('is_package_attr','=',True)]}" />
<field name="is_package_attr" invisible="1" />
</field>
Expand All @@ -33,7 +33,7 @@
<field name="inherit_id" ref="product.product_packaging_form_view" />
<field name="arch" type="xml">
<field name="product_tmpl_id" position="after">
<field name="product" />
<field name="product_id" />
</field>
</field>
</record>
Expand All @@ -44,7 +44,7 @@
<field name="inherit_id" ref="product.product_packaging_tree_view" />
<field name="arch" type="xml">
<field name="product_tmpl_id" position="after">
<field name="product" />
<field name="product_id" />
</field>
</field>
</record>
Expand All @@ -56,7 +56,7 @@
ref="product_packaging_views.product_ul_packaging_form_view" />
<field name="arch" type="xml">
<field name="product_tmpl_id" position="after">
<field name="product" />
<field name="product_id" />
</field>
</field>
</record>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<field name="inherit_id" ref="base.view_partner_form" />
<field name="arch" type="xml">
<field name="date" position="after">
<field name="partner_product_ul" />
<field name="partner_product_ul_id" />
</field>
</field>
</record>
Expand Down
2 changes: 1 addition & 1 deletion purchase_packaging_info/__openerp__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

{
"name": "Purchase - Packaging information",
"version": "1.0",
"version": "8.0.1.1.0",
"depends": [
"purchase",
"product_packaging_through_attributes",
Expand Down
22 changes: 22 additions & 0 deletions purchase_packaging_info/migrations/8.0.1.1.0/pre-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
# © 2016 Oihane Crucelaegui - AvanzOSC
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html


def update_columns(cr):
cr.execute(
"""
ALTER TABLE purchase_order
RENAME COLUMN product_ul TO product_ul_id
""")
cr.execute(
"""
ALTER TABLE purchase_order_line
RENAME COLUMN sec_pack TO sec_pack_id
""")


def migrate(cr, version):
if not version:
return
update_columns(cr)
47 changes: 24 additions & 23 deletions purchase_packaging_info/models/purchase_order.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
# -*- encoding: utf-8 -*-
##############################################################################
# For copyright and license notices, see __openerp__.py file in root directory
##############################################################################
from openerp import models, fields, api
# -*- coding: utf-8 -*-
# © 2014-2016 Oihane Crucelaegui - AvanzOSC
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from openerp import api, fields, models
from openerp.addons import decimal_precision as dp


class PurchaseOrder(models.Model):
_inherit = 'purchase.order'

product_ul = fields.Many2one(
product_ul_id = fields.Many2one(
comodel_name='product.ul', string='Logistic Unit', readonly=True,
states={'draft': [('readonly', False)]})

Expand All @@ -20,45 +21,45 @@ def onchange_partner_id(self, partner_id):
if not res.get('value'):
res['value'] = {}
res['value']['product_ul'] = (
partner.partner_product_ul.id or
partner.commercial_partner_id.partner_product_ul.id)
partner.partner_product_ul_id.id or
partner.commercial_partner_id.partner_product_ul_id.id)
return res

@api.one
@api.onchange('product_ul')
def onchange_product_ul(self):
for line in self.order_line:
line.sec_pack = line.sec_pack or self.product_ul
@api.onchange('product_ul_id')
def onchange_product_ul_id(self):
for record in self:
for line in record.order_line:
line.sec_pack_id = line.sec_pack_id or record.product_ul_id


class PurchaseOrderLine(models.Model):
_inherit = 'purchase.order.line'

@api.one
@api.depends('order_id.product_ul', 'product_id', 'product_qty',
'pri_pack', 'sec_pack')
'pri_pack_id', 'sec_pack_id')
def _calculate_packages(self):
package_attr = self.product_id.attribute_value_ids.filtered(
lambda x: x.attribute_id.is_package)
if package_attr:
self.pri_pack_qty = (
self.product_qty / (package_attr.numeric_value or 1.0))
if package_attr.package_product:
self.pri_pack = package_attr.package_product
for packaging in self.sec_pack.packagings:
if package_attr.package_product_id:
self.pri_pack_id = package_attr.package_product_id
for packaging in self.sec_pack_id.packagings:
if packaging.product == package_attr.package_product:
self.sec_pack_qty = (
self.pri_pack_qty / (
(packaging.ul_qty * packaging.rows) or 1.0))

pri_pack_qty = fields.Float(
string='# Pkg 1', compute='_calculate_packages', digits=(12, 2),
store=True)
pri_pack = fields.Many2one(
string='# Pkg 1', compute='_calculate_packages',
digits=dp.get_precision('Product Unit of Measure'), store=True)
pri_pack_id = fields.Many2one(
comodel_name='product.product', string='Pkg 1',
compute='_calculate_packages', readonly=True)
sec_pack_qty = fields.Float(
string='# Pkg 2', compute='_calculate_packages', digits=(12, 2),
store=True)
sec_pack = fields.Many2one(
string='# Pkg 2', compute='_calculate_packages',
digits=dp.get_precision('Product Unit of Measure'), store=True)
sec_pack_id = fields.Many2one(
comodel_name='product.ul', string='Pkg 2')
20 changes: 10 additions & 10 deletions purchase_packaging_info/views/purchase_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,24 @@
<field name="inherit_id" ref="purchase.purchase_order_form" />
<field name="arch" type="xml">
<field name="currency_id" position="after">
<field name="product_ul" groups="product.group_stock_packaging" />
<field name="product_ul_id" groups="product.group_stock_packaging" />
</field>
<field name="order_line" position="attributes">
<attribute name="context">{'default_product_ul': product_ul}</attribute>
<attribute name="context">{'default_product_ul': product_ul_id}</attribute>
</field>
<xpath expr="//field[@name='order_line']/tree//field[@name='product_uom']" position="after">
<field name="pri_pack_qty"
groups="product.group_stock_packaging"
sum="# Pkg 1"
/>
<field name="pri_pack"
<field name="pri_pack_id"
groups="product.group_stock_packaging"
/>
<field name="sec_pack_qty"
groups="product.group_stock_packaging"
sum="# Pkg 2"
/>
<field name="sec_pack"
<field name="sec_pack_id"
groups="product.group_stock_packaging"
/>
</xpath>
Expand All @@ -43,7 +43,7 @@
<field name="pri_pack_qty"
class="oe_inline"
/>
<field name="pri_pack"
<field name="pri_pack_id"
class="oe_inline oe_no_button"
groups="product.group_uom"
/>
Expand All @@ -53,7 +53,7 @@
<field name="sec_pack_qty"
class="oe_inline"
/>
<field name="sec_pack"
<field name="sec_pack_id"
class="oe_inline oe_no_button"
groups="product.group_uom"
/>
Expand All @@ -73,7 +73,7 @@
<field name="pri_pack_qty"
class="oe_inline"
/>
<field name="pri_pack"
<field name="pri_pack_id"
class="oe_inline oe_no_button"
groups="product.group_uom"
/>
Expand All @@ -83,7 +83,7 @@
<field name="sec_pack_qty"
class="oe_inline"
/>
<field name="sec_pack"
<field name="sec_pack_id"
class="oe_inline oe_no_button"
groups="product.group_uom"
/>
Expand All @@ -102,14 +102,14 @@
groups="product.group_stock_packaging"
sum="# Pkg 1"
/>
<field name="pri_pack"
<field name="pri_pack_id"
groups="product.group_stock_packaging"
/>
<field name="sec_pack_qty"
groups="product.group_stock_packaging"
sum="# Pkg 2"
/>
<field name="sec_pack"
<field name="sec_pack_id"
groups="product.group_stock_packaging"
/>
</field>
Expand Down
2 changes: 1 addition & 1 deletion sale_packaging_info/__openerp__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

{
"name": "Sale - Packaging information",
"version": "8.0.1.0.0",
"version": "8.0.1.1.0",
"license": "AGPL-3",
"depends": [
"sale",
Expand Down
22 changes: 22 additions & 0 deletions sale_packaging_info/migrations/8.0.1.1.0/pre-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
# © 2016 Oihane Crucelaegui - AvanzOSC
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html


def update_columns(cr):
cr.execute(
"""
ALTER TABLE sale_order
RENAME COLUMN product_ul TO product_ul_id
""")
cr.execute(
"""
ALTER TABLE sale_order_line
RENAME COLUMN sec_pack TO sec_pack_id
""")


def migrate(cr, version):
if not version:
return
update_columns(cr)
Loading

0 comments on commit 4b25c02

Please sign in to comment.