Merge lp:~joao-gama/openerp-product-attributes/product_weight into lp:~product-core-editors/openerp-product-attributes/7.0

Proposed by Joao Alfredo Gama Batista
Status: Merged
Merged at revision: 197
Proposed branch: lp:~joao-gama/openerp-product-attributes/product_weight
Merge into: lp:~product-core-editors/openerp-product-attributes/7.0
Diff against target: 267 lines (+236/-0)
6 files modified
product_weight/__init__.py (+23/-0)
product_weight/__openerp__.py (+43/-0)
product_weight/product_view.xml (+21/-0)
product_weight/wizard/__init__.py (+23/-0)
product_weight/wizard/product_weight_update.py (+92/-0)
product_weight/wizard/product_weight_update_view.xml (+34/-0)
To merge this branch: bzr merge lp:~joao-gama/openerp-product-attributes/product_weight
Reviewer Review Type Date Requested Status
Maxime Chambreuil (http://www.savoirfairelinux.com) Approve
Guewen Baconnier @ Camptocamp Pending
Review via email: mp+144982@code.launchpad.net

This proposal supersedes a proposal from 2013-01-17.

Description of the change

Add the module product_weight that calculates the product's net weight based on the product's components weight.

To post a comment you must log in.
Revision history for this message
Maxime Chambreuil (http://www.savoirfairelinux.com) (max3903) wrote : Posted in a previous version of this proposal

LGTM, not tested.

review: Approve
Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote : Posted in a previous version of this proposal

Hello,

There is a real problem with the target branch lp:openerp-product-attributes/6.1

I had to rebuild it entirely from the history of the other branches.

You can read details here: https://code.launchpad.net/~product-core-editors/openerp-product-attributes/new6.1/+merge/143657

So, it means that this branch should be replaced. Can you propose again your merge when the branch will be replaced please ?

Sorry for the trouble.

Guewen

review: Abstain
Revision history for this message
Maxime Chambreuil (http://www.savoirfairelinux.com) (max3903) wrote : Posted in a previous version of this proposal

Target branch of this MP is 7.0.

Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote : Posted in a previous version of this proposal

The 7.0 branch will have the same issue, the 'common ancestor' of the branches have to be the same than the extra-addons otherwise the merges won't work correctly.

Revision history for this message
Joao Alfredo Gama Batista (joao-gama) wrote : Posted in a previous version of this proposal

Hi Guewen,

No problem in proposing the merge again. Just let me know when the
branch will be replaced.

Thanks.

Joao

Le 2013-01-18 03:53, Guewen Baconnier @ Camptocamp a écrit :
> Review: Abstain
>
> Hello,
>
> There is a real problem with the target branch lp:openerp-product-attributes/6.1
>
> I had to rebuild it entirely from the history of the other branches.
>
> You can read details here: https://code.launchpad.net/~product-core-editors/openerp-product-attributes/new6.1/+merge/143657
>
> So, it means that this branch should be replaced. Can you propose again your merge when the branch will be replaced please ?
>
> Sorry for the trouble.
>
> Guewen
>

--
Joao Alfredo Gama Batista
Consultant en Logiciel Libre
Savoir-faire Linux inc.
<email address hidden>
+1 514 276-5468 poste 163

Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote : Posted in a previous version of this proposal

Hi Joao,

The branch is now rebuild properly.

Have a nice day
Guewen

Revision history for this message
Maxime Chambreuil (http://www.savoirfairelinux.com) (max3903) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added directory 'product_weight'
2=== added file 'product_weight/__init__.py'
3--- product_weight/__init__.py 1970-01-01 00:00:00 +0000
4+++ product_weight/__init__.py 2013-01-25 16:50:28 +0000
5@@ -0,0 +1,23 @@
6+# -*- coding: utf-8 -*-
7+
8+##############################################################################
9+#
10+# OpenERP, Open Source Management Solution
11+# Copyright (C) 2013 Savoir-faire Linux (<http://www.savoirfairelinux.com>).
12+#
13+# This program is free software: you can redistribute it and/or modify
14+# it under the terms of the GNU Affero General Public License as
15+# published by the Free Software Foundation, either version 3 of the
16+# License, or (at your option) any later version.
17+#
18+# This program is distributed in the hope that it will be useful,
19+# but WITHOUT ANY WARRANTY; without even the implied warranty of
20+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21+# GNU Affero General Public License for more details.
22+#
23+# You should have received a copy of the GNU Affero General Public License
24+# along with this program. If not, see <http://www.gnu.org/licenses/>.
25+#
26+##############################################################################
27+
28+import wizard
29
30=== added file 'product_weight/__openerp__.py'
31--- product_weight/__openerp__.py 1970-01-01 00:00:00 +0000
32+++ product_weight/__openerp__.py 2013-01-25 16:50:28 +0000
33@@ -0,0 +1,43 @@
34+# -*- coding: utf-8 -*-
35+
36+##############################################################################
37+#
38+# OpenERP, Open Source Management Solution
39+# Copyright (C) 2013 Savoir-faire Linux (<http://www.savoirfairelinux.com>).
40+#
41+# This program is free software: you can redistribute it and/or modify
42+# it under the terms of the GNU Affero General Public License as
43+# published by the Free Software Foundation, either version 3 of the
44+# License, or (at your option) any later version.
45+#
46+# This program is distributed in the hope that it will be useful,
47+# but WITHOUT ANY WARRANTY; without even the implied warranty of
48+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
49+# GNU Affero General Public License for more details.
50+#
51+# You should have received a copy of the GNU Affero General Public License
52+# along with this program. If not, see <http://www.gnu.org/licenses/>.
53+#
54+##############################################################################
55+
56+{
57+ "name": "Product Weight Calculation",
58+ "version": "0.1",
59+ "author": "Savoir-faire Linux",
60+ "website": "http://www.savoirfairelinux.com",
61+ "license": "AGPL-3",
62+ "category": "Warehouse",
63+ "description": """
64+ This module updates product net weight based on it's components weight
65+ """,
66+ "depends": [
67+ "base",
68+ "mrp",
69+ ],
70+ "demo": [],
71+ "data": [
72+ "wizard/product_weight_update_view.xml",
73+ "product_view.xml",
74+ ],
75+ "installable": True,
76+}
77
78=== added file 'product_weight/product_view.xml'
79--- product_weight/product_view.xml 1970-01-01 00:00:00 +0000
80+++ product_weight/product_view.xml 2013-01-25 16:50:28 +0000
81@@ -0,0 +1,21 @@
82+<?xml version="1.0" encoding="utf-8"?>
83+<openerp>
84+ <data>
85+ <record id="product_weight_form_view" model="ir.ui.view">
86+ <field name="name">product.weight.form</field>
87+ <field name="model">product.product</field>
88+ <field name="inherit_id" ref="product.product_normal_form_view"/>
89+ <field name="arch" type="xml">
90+ <data>
91+ <field name="weight_net" position="replace">
92+ <label for="weight_net" />
93+ <div>
94+ <field name="weight_net" attrs="{'readonly': [('type','=','service')]}" class="oe_inline" />
95+ <button name="%(action_view_product_weight_update)d" type="action" string="update" attrs="{'invisible':[('type','=','service')]}" class="oe_link" />
96+ </div>
97+ </field>
98+ </data>
99+ </field>
100+ </record>
101+ </data>
102+</openerp>
103
104=== added directory 'product_weight/wizard'
105=== added file 'product_weight/wizard/__init__.py'
106--- product_weight/wizard/__init__.py 1970-01-01 00:00:00 +0000
107+++ product_weight/wizard/__init__.py 2013-01-25 16:50:28 +0000
108@@ -0,0 +1,23 @@
109+# -*- coding: utf-8 -*-
110+
111+##############################################################################
112+#
113+# OpenERP, Open Source Management Solution
114+# Copyright (C) 2013 Savoir-faire Linux (<http://www.savoirfairelinux.com>).
115+#
116+# This program is free software: you can redistribute it and/or modify
117+# it under the terms of the GNU Affero General Public License as
118+# published by the Free Software Foundation, either version 3 of the
119+# License, or (at your option) any later version.
120+#
121+# This program is distributed in the hope that it will be useful,
122+# but WITHOUT ANY WARRANTY; without even the implied warranty of
123+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
124+# GNU Affero General Public License for more details.
125+#
126+# You should have received a copy of the GNU Affero General Public License
127+# along with this program. If not, see <http://www.gnu.org/licenses/>.
128+#
129+##############################################################################
130+
131+import product_weight_update
132
133=== added file 'product_weight/wizard/product_weight_update.py'
134--- product_weight/wizard/product_weight_update.py 1970-01-01 00:00:00 +0000
135+++ product_weight/wizard/product_weight_update.py 2013-01-25 16:50:28 +0000
136@@ -0,0 +1,92 @@
137+# -*- coding: utf-8 -*-
138+
139+##############################################################################
140+#
141+# OpenERP, Open Source Management Solution
142+# Copyright (C) 2013 Savoir-faire Linux (<http://www.savoirfairelinux.com>).
143+#
144+# This program is free software: you can redistribute it and/or modify
145+# it under the terms of the GNU Affero General Public License as
146+# published by the Free Software Foundation, either version 3 of the
147+# License, or (at your option) any later version.
148+#
149+# This program is distributed in the hope that it will be useful,
150+# but WITHOUT ANY WARRANTY; without even the implied warranty of
151+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
152+# GNU Affero General Public License for more details.
153+#
154+# You should have received a copy of the GNU Affero General Public License
155+# along with this program. If not, see <http://www.gnu.org/licenses/>.
156+#
157+##############################################################################
158+
159+import logging
160+from openerp.osv import fields, osv
161+from openerp.tools.translate import _
162+
163+_logger = logging.getLogger(__name__)
164+
165+
166+class product_weight_update(osv.osv_memory):
167+ _name = "product.weight.update"
168+ _description = "Update Product Weight"
169+ _columns = {
170+ 'product_id': fields.many2one('product.product', 'Product'),
171+ 'bom_id': fields.many2one('mrp.bom', 'BoM', domain="[('product_id', '=', product_id)]"),
172+ }
173+
174+ def default_get(self, cr, uid, fields, context):
175+ """ To get default values for the object.
176+ @param self: The object pointer.
177+ @param cr: A database cursor
178+ @param uid: ID of the user currently logged in
179+ @param fields: List of fields for which we want default values
180+ @param context: A standard dictionary
181+ @return: A dictionary which of fields with values.
182+ """
183+ product_id = context and context.get('active_id', False) or False
184+ res = super(product_weight_update, self).default_get(cr, uid, fields, context=context)
185+
186+ bom_id = self.pool.get('mrp.bom').search(
187+ cr, uid, [('product_id', '=', product_id)])[0]
188+
189+ if 'product_id' in fields:
190+ res.update({'product_id': product_id})
191+
192+ res.update({'bom_id': bom_id})
193+
194+ return res
195+
196+ def update_weight(self, cr, uid, ids, context=None):
197+ mrp_bom = self.pool.get("mrp.bom")
198+ product_uom_categ = self.pool.get("product.uom.categ")
199+ product_product = self.pool.get("product.product")
200+
201+ if context is None:
202+ context = {}
203+
204+ rec_id = context and context.get('active_id', False)
205+ assert rec_id, _('Active ID is not set in Context')
206+
207+ for i in self.browse(cr, uid, ids, context=context):
208+ weight_net = 0.0
209+ bom_ids = mrp_bom.search(cr, uid,
210+ [('bom_id', '=', i.bom_id.id)])
211+ for bom in mrp_bom.browse(cr, uid, bom_ids, context=context):
212+ _logger.warning(_('Weight'))
213+ if bom.product_uom.category_id.id == 2:
214+ weight_net += bom.product_qty
215+ else:
216+ weight_net += (bom.product_qty * bom.product_id.weight_net)
217+
218+ _logger.warning("%s (%s): %0.2f" % (
219+ bom.product_id.name,
220+ bom.product_uom.category_id.name, weight_net))
221+ weight_net = weight_net / mrp_bom.browse(
222+ cr, uid, i.bom_id.id, context=context).product_qty
223+ product_product.write(cr, uid, rec_id,
224+ {'weight_net': weight_net},
225+ context=context)
226+ return {}
227+
228+product_weight_update()
229
230=== added file 'product_weight/wizard/product_weight_update_view.xml'
231--- product_weight/wizard/product_weight_update_view.xml 1970-01-01 00:00:00 +0000
232+++ product_weight/wizard/product_weight_update_view.xml 2013-01-25 16:50:28 +0000
233@@ -0,0 +1,34 @@
234+<?xml version="1.0" encoding="utf-8"?>
235+<openerp>
236+ <data>
237+ <record id="view_product_weight_update" model="ir.ui.view">
238+ <field name="name">Update Product Weight</field>
239+ <field name="model">product.weight.update</field>
240+ <field name="arch" type="xml">
241+ <form string="Update Product Weight" version="7.0">
242+ <group>
243+ <field name="product_id" invisible="1" />
244+ <field name="bom_id" />
245+ </group>
246+ <footer>
247+ <button name="update_weight" string="_Apply" type="object" class="oe_highlight"/>
248+ or
249+ <button string="Cancel" class="oe_link" special="cancel" />
250+ </footer>
251+ </form>
252+ </field>
253+ </record>
254+
255+ <record id="action_view_product_weight_update" model="ir.actions.act_window">
256+ <field name="name">Update Product Weight</field>
257+ <field name="type">ir.actions.act_window</field>
258+ <field name="res_model">product.weight.update</field>
259+ <field name="view_type">form</field>
260+ <field name="view_mode">form</field>
261+ <field name="view_id" ref="view_product_weight_update"/>
262+ <field name="target">new</field>
263+ </record>
264+
265+ </data>
266+</openerp>
267+

Subscribers

People subscribed via source and target branches