← Back to team overview

openerp-community team mailing list archive

lp:~savoirfairelinux-openerp/openerp-product-attributes/product_dependencies into lp:openerp-product-attributes

 

Joao Alfredo Gama Batista has proposed merging lp:~savoirfairelinux-openerp/openerp-product-attributes/product_dependencies into lp:openerp-product-attributes.

Requested reviews:
  Maxime Chambreuil (http://www.savoirfairelinux.com) (max3903)

For more details, see:
https://code.launchpad.net/~savoirfairelinux-openerp/openerp-product-attributes/product_dependencies/+merge/185082

Added the module product_dependencies. This module adds a dependencies tab to the product so we can add a list of products/categories that the current product depends on.
 
-- 
https://code.launchpad.net/~savoirfairelinux-openerp/openerp-product-attributes/product_dependencies/+merge/185082
Your team OpenERP Community is subscribed to branch lp:openerp-product-attributes.
=== added directory 'product_dependencies'
=== added file 'product_dependencies/__init__.py'
--- product_dependencies/__init__.py	1970-01-01 00:00:00 +0000
+++ product_dependencies/__init__.py	2013-09-11 15:15:03 +0000
@@ -0,0 +1,23 @@
+# -*- coding: utf-8 -*-
+
+##############################################################################
+#
+#    OpenERP, Open Source Management Solution
+#    Copyright (C) 2013 Savoirfaire-Linux Inc. (<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

=== added file 'product_dependencies/__openerp__.py'
--- product_dependencies/__openerp__.py	1970-01-01 00:00:00 +0000
+++ product_dependencies/__openerp__.py	2013-09-11 15:15:03 +0000
@@ -0,0 +1,37 @@
+# -*- coding: utf-8 -*-
+
+##############################################################################
+#
+#    OpenERP, Open Source Management Solution
+#    Copyright (C) 2013 Savoirfaire-Linux Inc. (<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 Dependencies',
+    'version': '1.0',
+    'category': 'Product Management',
+    'description': """Allows products to have other products/categories as dependencies. This module is primarily used by the contract_isp_wizard module to create packages based on basic product selections but it can be used by others modules that manage product lists.""",
+    'author': 'Savoirfaire-Linux Inc',
+    'website': 'www.savoirfairelinux.com',
+    'license': 'AGPL-3',
+    'depends': ['product'],
+    'data': [
+        'product_dependencies_view.xml', 
+    ],
+    'active': False,
+    'installable': True,
+}

=== added directory 'product_dependencies/i18n'
=== added file 'product_dependencies/i18n/product_dependecies.pot'
=== added file 'product_dependencies/product.py'
--- product_dependencies/product.py	1970-01-01 00:00:00 +0000
+++ product_dependencies/product.py	2013-09-11 15:15:03 +0000
@@ -0,0 +1,83 @@
+# -*- coding: utf-8 -*-
+
+##############################################################################
+#
+#    OpenERP, Open Source Management Solution
+#    Copyright (C) 2013 Savoirfaire-Linux Inc. (<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/>.
+#
+##############################################################################
+
+from openerp.osv import orm, fields
+
+
+class product_dependency(orm.Model):
+    _name = 'product.dependency'
+
+    _columns = {
+        'name': fields.char('Name'),
+        'type': fields.selection((('product', 'Product'),
+                                  ('category', 'Category')),
+                                 'Type'),
+        'product_id': fields.many2one('product.product',
+                                      string='Product Dependency'),
+        'category_id': fields.many2one('product.category',
+                                       string='Category Dependency'),
+        'auto': fields.boolean('Automatically added'),
+        'product_id': fields.many2one('product.product')
+    }
+
+    _defaults = {
+        'type': 'product'
+    }
+
+    def onchange_type(self, cr, uid, ids, type_name):
+        values = {'value': {}}
+        if type_name == 'product':
+            values['value']['category_id'] = None
+        elif type_name == 'category':
+            values['value']['product_id'] = None
+
+        values['name'] = ''
+
+        return values
+
+    def onchange_product_id(self, cr, uid, ids, product_id):
+        values = {'value': {'name': None}}
+        if product_id:
+            name = self.pool.get('product.product').browse(cr, uid, product_id, context={}).name
+            values['value']['name'] = '%s (Product)' % name
+
+        return values
+
+    def onchange_category_id(self, cr, uid, ids, category_id):
+        values = {'value': {'name': None}}
+        if category_id:
+            name = self.pool.get('product.category').browse(cr, uid, category_id, context={}).name
+            values['value']['name'] = '%s (Category)' % name
+
+        return values
+
+
+class product_product(orm.Model):
+    _inherit = 'product.product'
+
+    _columns = {
+        'dependency_ids': fields.many2many('product.dependency',
+                                           'product_product_dependency_rel',
+                                           'dependency_id',
+                                           'product_id',
+                                           string='Dependencies')
+    }

=== added file 'product_dependencies/product_dependencies_view.xml'
--- product_dependencies/product_dependencies_view.xml	1970-01-01 00:00:00 +0000
+++ product_dependencies/product_dependencies_view.xml	2013-09-11 15:15:03 +0000
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="utf-8"?>
+<openerp>
+    <data>
+	<record id="view_product_dependecies_product_form" model="ir.ui.view">
+	    <field name="name">product.dependencies.product.form</field>
+	    <field name="model">product.product</field>
+	    <field name="inherit_id" ref="product.product_normal_form_view"/>
+	    <field name="arch" type="xml">
+		<xpath expr="//page[@string='Sales']" position="after">
+		    <page string="Dependencies">
+			<group string="Dependencies">
+			    <field name="dependency_ids" mode="tree" nolabel="1">
+				<tree version="7">
+				    <field name="type" on_change="onchange_type(type)" />
+				    <field name="name" />
+				    <field name="product_id" invisible="1" />
+				    <field name="category_id" invisible="1" />
+				    <field name="auto" />
+				</tree>
+			    </field>
+			</group>
+		    </page>
+		</xpath>
+	    </field>
+	</record>
+	<record id="view_product_dependecies_form" model="ir.ui.view">
+	    <field name="name">product.dependencies.form</field>
+	    <field name="model">product.dependency</field>
+	    <field name="arch" type="xml">
+		<form string="Dependency" version="7.0">
+		    <group>
+			<field name="type" on_change="onchange_type(type)" required="1" />
+			<field 
+			    on_change="onchange_product_id(product_id)"
+			    name="product_id"
+			    attrs="{'invisible': [('type', '&lt;&gt;', 'product')], 'required': [('type', '=', 'product')]}" />
+			<field 
+			    on_change="onchange_category_id(category_id)"
+			    name="category_id"
+			    attrs="{'invisible': [('type', '&lt;&gt;', 'category')], 'required': [('type', '=', 'category')]}" />
+			<field name="auto" />
+			<field name="name" invisible="1" />
+		    </group>
+		</form>
+	    </field>
+	</record>
+    </data>
+</openerp>


Follow ups