← Back to team overview

openerp-community team mailing list archive

[Merge] lp:~joao-gama/openerp-product-attributes/product_weight into lp:openerp-product-attributes

 

Joao Alfredo Gama Batista has proposed merging lp:~joao-gama/openerp-product-attributes/product_weight into lp:openerp-product-attributes.

Requested reviews:
  Guewen Baconnier @ Camptocamp (gbaconnier-c2c)
  Maxime Chambreuil (http://www.savoirfairelinux.com) (max3903)

For more details, see:
https://code.launchpad.net/~joao-gama/openerp-product-attributes/product_weight/+merge/144982

Add the module product_weight that calculates the product's net weight based on the product's components weight.
-- 
https://code.launchpad.net/~joao-gama/openerp-product-attributes/product_weight/+merge/144982
Your team OpenERP Community is subscribed to branch lp:openerp-product-attributes.
=== added directory 'product_weight'
=== added file 'product_weight/__init__.py'
--- product_weight/__init__.py	1970-01-01 00:00:00 +0000
+++ product_weight/__init__.py	2013-01-25 16:50:28 +0000
@@ -0,0 +1,23 @@
+# -*- coding: utf-8 -*-
+
+##############################################################################
+#
+#    OpenERP, Open Source Management Solution
+#    Copyright (C) 2013 Savoir-faire Linux (<http://www.savoirfairelinux.com>).
+#
+#    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 wizard

=== added file 'product_weight/__openerp__.py'
--- product_weight/__openerp__.py	1970-01-01 00:00:00 +0000
+++ product_weight/__openerp__.py	2013-01-25 16:50:28 +0000
@@ -0,0 +1,43 @@
+# -*- coding: utf-8 -*-
+
+##############################################################################
+#
+#    OpenERP, Open Source Management Solution
+#    Copyright (C) 2013 Savoir-faire Linux (<http://www.savoirfairelinux.com>).
+#
+#    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": "Product Weight Calculation",
+    "version": "0.1",
+    "author": "Savoir-faire Linux",
+    "website": "http://www.savoirfairelinux.com";,
+    "license": "AGPL-3",
+    "category": "Warehouse",
+    "description": """
+    This module updates product net weight based on it's components weight
+    """,
+    "depends": [
+        "base",
+        "mrp",
+    ],
+    "demo": [],
+    "data": [
+        "wizard/product_weight_update_view.xml",
+        "product_view.xml",
+    ],
+    "installable": True,
+}

=== added file 'product_weight/product_view.xml'
--- product_weight/product_view.xml	1970-01-01 00:00:00 +0000
+++ product_weight/product_view.xml	2013-01-25 16:50:28 +0000
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<openerp>
+  <data>
+    <record id="product_weight_form_view" model="ir.ui.view">
+      <field name="name">product.weight.form</field>
+      <field name="model">product.product</field>
+      <field name="inherit_id" ref="product.product_normal_form_view"/>
+      <field name="arch" type="xml">
+	<data>
+	  <field name="weight_net" position="replace">
+	    <label for="weight_net" />
+	    <div>
+	      <field name="weight_net" attrs="{'readonly': [('type','=','service')]}" class="oe_inline" />
+	      <button name="%(action_view_product_weight_update)d" type="action" string="update" attrs="{'invisible':[('type','=','service')]}" class="oe_link" />
+	    </div>
+	  </field>
+	</data>
+      </field>
+    </record>
+  </data>
+</openerp>

=== added directory 'product_weight/wizard'
=== added file 'product_weight/wizard/__init__.py'
--- product_weight/wizard/__init__.py	1970-01-01 00:00:00 +0000
+++ product_weight/wizard/__init__.py	2013-01-25 16:50:28 +0000
@@ -0,0 +1,23 @@
+# -*- coding: utf-8 -*-
+
+##############################################################################
+#
+#    OpenERP, Open Source Management Solution
+#    Copyright (C) 2013 Savoir-faire Linux (<http://www.savoirfairelinux.com>).
+#
+#    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 product_weight_update

=== added file 'product_weight/wizard/product_weight_update.py'
--- product_weight/wizard/product_weight_update.py	1970-01-01 00:00:00 +0000
+++ product_weight/wizard/product_weight_update.py	2013-01-25 16:50:28 +0000
@@ -0,0 +1,92 @@
+# -*- coding: utf-8 -*-
+
+##############################################################################
+#
+#    OpenERP, Open Source Management Solution
+#    Copyright (C) 2013 Savoir-faire Linux (<http://www.savoirfairelinux.com>).
+#
+#    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 logging
+from openerp.osv import fields, osv
+from openerp.tools.translate import _
+
+_logger = logging.getLogger(__name__)
+
+
+class product_weight_update(osv.osv_memory):
+    _name = "product.weight.update"
+    _description = "Update Product Weight"
+    _columns = {
+        'product_id': fields.many2one('product.product', 'Product'),
+        'bom_id': fields.many2one('mrp.bom', 'BoM', domain="[('product_id', '=', product_id)]"),
+    }
+
+    def default_get(self, cr, uid, fields, context):
+        """ To get default values for the object.
+         @param self: The object pointer.
+         @param cr: A database cursor
+         @param uid: ID of the user currently logged in
+         @param fields: List of fields for which we want default values
+         @param context: A standard dictionary
+         @return: A dictionary which of fields with values.
+        """
+        product_id = context and context.get('active_id', False) or False
+        res = super(product_weight_update, self).default_get(cr, uid, fields, context=context)
+
+        bom_id = self.pool.get('mrp.bom').search(
+            cr, uid, [('product_id', '=', product_id)])[0]
+
+        if 'product_id' in fields:
+            res.update({'product_id': product_id})
+
+        res.update({'bom_id': bom_id})
+
+        return res
+
+    def update_weight(self, cr, uid, ids, context=None):
+        mrp_bom = self.pool.get("mrp.bom")
+        product_uom_categ = self.pool.get("product.uom.categ")
+        product_product = self.pool.get("product.product")
+
+        if context is None:
+            context = {}
+
+        rec_id = context and context.get('active_id', False)
+        assert rec_id, _('Active ID is not set in Context')
+
+        for i in self.browse(cr, uid, ids, context=context):
+            weight_net = 0.0
+            bom_ids = mrp_bom.search(cr, uid,
+                                     [('bom_id', '=', i.bom_id.id)])
+            for bom in mrp_bom.browse(cr, uid, bom_ids, context=context):
+                _logger.warning(_('Weight'))
+                if bom.product_uom.category_id.id == 2:
+                    weight_net += bom.product_qty
+                else:
+                    weight_net += (bom.product_qty * bom.product_id.weight_net)
+
+                _logger.warning("%s (%s): %0.2f" % (
+                    bom.product_id.name,
+                    bom.product_uom.category_id.name, weight_net))
+            weight_net = weight_net / mrp_bom.browse(
+                cr, uid, i.bom_id.id, context=context).product_qty
+            product_product.write(cr, uid, rec_id,
+                       {'weight_net': weight_net},
+                       context=context)
+        return {}
+
+product_weight_update()

=== added file 'product_weight/wizard/product_weight_update_view.xml'
--- product_weight/wizard/product_weight_update_view.xml	1970-01-01 00:00:00 +0000
+++ product_weight/wizard/product_weight_update_view.xml	2013-01-25 16:50:28 +0000
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="utf-8"?>
+<openerp>
+  <data>
+    <record id="view_product_weight_update" model="ir.ui.view">
+      <field name="name">Update Product Weight</field>
+      <field name="model">product.weight.update</field>
+      <field name="arch" type="xml">
+	<form string="Update Product Weight" version="7.0">
+	  <group>
+	    <field name="product_id" invisible="1" />
+	    <field name="bom_id" />
+	  </group>
+	  <footer>
+	    <button name="update_weight" string="_Apply" type="object" class="oe_highlight"/>
+	    or
+	    <button string="Cancel" class="oe_link" special="cancel" />
+	  </footer>
+	</form>
+      </field>
+    </record>
+
+    <record id="action_view_product_weight_update" model="ir.actions.act_window">
+      <field name="name">Update Product Weight</field>
+      <field name="type">ir.actions.act_window</field>
+      <field name="res_model">product.weight.update</field>
+      <field name="view_type">form</field>
+      <field name="view_mode">form</field>
+      <field name="view_id" ref="view_product_weight_update"/>
+      <field name="target">new</field>
+    </record>
+    
+  </data>
+</openerp>
+


Follow ups