From 7c09ab2ea224669e70c7725e826d690a7d02cbed Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Wed, 2 Jul 2014 22:06:55 +0200 Subject: [PATCH] Add module partner_products_shortcut. --- partner_products_shortcut/__init__.py | 24 +++++++++++ partner_products_shortcut/__openerp__.py | 45 ++++++++++++++++++++ partner_products_shortcut/partner.py | 48 ++++++++++++++++++++++ partner_products_shortcut/partner_view.xml | 37 +++++++++++++++++ partner_products_shortcut/product.py | 44 ++++++++++++++++++++ 5 files changed, 198 insertions(+) create mode 100644 partner_products_shortcut/__init__.py create mode 100644 partner_products_shortcut/__openerp__.py create mode 100644 partner_products_shortcut/partner.py create mode 100644 partner_products_shortcut/partner_view.xml create mode 100644 partner_products_shortcut/product.py diff --git a/partner_products_shortcut/__init__.py b/partner_products_shortcut/__init__.py new file mode 100644 index 0000000..cc7a74b --- /dev/null +++ b/partner_products_shortcut/__init__.py @@ -0,0 +1,24 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# Partner Products Shortcut module for OpenERP +# Copyright (C) 2014 Akretion (http://www.akretion.com) +# @author Alexis de Lattre +# +# 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 . +# +############################################################################## + +from . import product +from . import partner diff --git a/partner_products_shortcut/__openerp__.py b/partner_products_shortcut/__openerp__.py new file mode 100644 index 0000000..2039feb --- /dev/null +++ b/partner_products_shortcut/__openerp__.py @@ -0,0 +1,45 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# Partner Products Shortcut module for OpenERP +# Copyright (C) 2014 Akretion (http://www.akretion.com) +# @author Alexis de Lattre +# +# 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 . +# +############################################################################## + + +{ + 'name': 'Partner Products Shortcut', + 'version': '0.1', + 'category': 'Contact Management', + 'license': 'AGPL-3', + 'summary': 'Adds a shortcut on partner form to the products supplied by this partner', + 'description': """ +Partner Products Shortcut +========================= + +Adds a shortcut on supplier partner form to the products supplied by this partner. + +Please contact Alexis de Lattre from Akretion for any help or question about this module. + """, + 'author': 'Akretion', + 'website': 'http://www.akretion.com', + 'depends': ['product'], + 'data': [ + 'partner_view.xml', + ], + 'active': False, +} diff --git a/partner_products_shortcut/partner.py b/partner_products_shortcut/partner.py new file mode 100644 index 0000000..6559674 --- /dev/null +++ b/partner_products_shortcut/partner.py @@ -0,0 +1,48 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# Partner Products Shortcut module for OpenERP +# Copyright (C) 2014 Akretion (http://www.akretion.com) +# @author Alexis de Lattre +# +# 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 . +# +############################################################################## + +from openerp.osv import orm, fields + + +class res_partner(orm.Model): + _inherit = 'res.partner' + + def _product_supplied_count( + self, cr, uid, ids, field_name, arg, context=None): + res = dict(map(lambda x: (x, 0), ids)) + try: + for partner_id in ids: + seller_ids = self.pool['product.supplierinfo'].search( + cr, uid, [('name', '=', partner_id)], context=context) + pt_ids = self.pool['product.template'].search( + cr, uid, [('seller_ids', 'in', seller_ids)], + context=context) + res[partner_id] = len(pt_ids) + except: + pass + return res + + _columns = { + 'product_supplied_count': fields.function( + _product_supplied_count, string="# of Products Supplied", + type='integer'), + } diff --git a/partner_products_shortcut/partner_view.xml b/partner_products_shortcut/partner_view.xml new file mode 100644 index 0000000..c4459ff --- /dev/null +++ b/partner_products_shortcut/partner_view.xml @@ -0,0 +1,37 @@ + + + + + + + + + Products + product.template + kanban,tree,form + {'search_default_seller_id': active_id} + + + + add.shortcut.to.products.partner.form + res.partner + + + + + + + + + + diff --git a/partner_products_shortcut/product.py b/partner_products_shortcut/product.py new file mode 100644 index 0000000..42b3724 --- /dev/null +++ b/partner_products_shortcut/product.py @@ -0,0 +1,44 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# Partner Products Shortcut module for OpenERP +# Copyright (C) 2014 Akretion (http://www.akretion.com) +# @author Alexis de Lattre +# +# 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 . +# +############################################################################## + +from openerp.osv import orm + + +class product_template(orm.Model): + _inherit = 'product.template' + + def search( + self, cr, uid, args, offset=0, limit=None, order=None, + context=None, count=False): + if context is None: + context = {} + seller_id = context.get('search_default_seller_id') + if seller_id: + seller_ids = self.pool['product.supplierinfo'].search( + cr, uid, [('name', '=', seller_id)], context=context) + for argument in args: + if isinstance(argument, list) and argument[0] == 'seller_ids': + args.remove(argument) + args.append((('seller_ids', 'in', seller_ids))) + return super(product_template, self).search( + cr, uid, args, offset=offset, limit=limit, order=order, + context=context, count=count)