diff --git a/partner_product_variants_shortcut/__init__.py b/partner_product_variants_shortcut/__init__.py new file mode 100644 index 0000000..428c04a --- /dev/null +++ b/partner_product_variants_shortcut/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- + +from . import product +from . import partner diff --git a/partner_product_variants_shortcut/__openerp__.py b/partner_product_variants_shortcut/__openerp__.py new file mode 100644 index 0000000..3dc9266 --- /dev/null +++ b/partner_product_variants_shortcut/__openerp__.py @@ -0,0 +1,47 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Partner Product Variants Shortcut module for Odoo +# Copyright (C) 2014-2016 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 Product Variants 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 Product Variants Shortcut +================================= + +Adds a shortcut on supplier partner form to the products supplied by this partner (display the product variants view). + +This module is an alternative to the module *partner_products_shortcut* ; the only difference is that it displays the product variants view (product.product) instead of the product view (product.template). + +This module has been written by Alexis de Lattre from Akretion +. + """, + 'author': 'Akretion', + 'website': 'http://www.akretion.com', + 'depends': ['product'], + 'conflicts': ['partner_products_shortcut'], + 'data': ['partner_view.xml'], + 'installable': True, +} diff --git a/partner_product_variants_shortcut/partner.py b/partner_product_variants_shortcut/partner.py new file mode 100644 index 0000000..64b7a91 --- /dev/null +++ b/partner_product_variants_shortcut/partner.py @@ -0,0 +1,42 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Partner Product Variants Shortcut module for Odoo +# Copyright (C) 2014-2016 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 import models, fields, api + + +class ResPartner(models.Model): + _inherit = 'res.partner' + + @api.one + def _product_supplied_count(self): + try: + sellers = self.env['product.supplierinfo'].search( + [('name', '=', self.id)]) + pproducts = self.env['product.product'].search( + [('seller_ids', 'in', sellers.ids)]) + self.product_supplied_count = len(pproducts) + except: + pass + + product_supplied_count = fields.Integer( + compute='_product_supplied_count', string="# of Products Supplied", + readonly=True) diff --git a/partner_product_variants_shortcut/partner_view.xml b/partner_product_variants_shortcut/partner_view.xml new file mode 100644 index 0000000..fe1977c --- /dev/null +++ b/partner_product_variants_shortcut/partner_view.xml @@ -0,0 +1,37 @@ + + + + + + + + + Product Variants + product.product + tree,form,kanban + {'search_default_seller_id': active_id} + + + + add.shortcut.to.product.variants.partner.form + res.partner + + + + + + + + + + diff --git a/partner_product_variants_shortcut/product.py b/partner_product_variants_shortcut/product.py new file mode 100644 index 0000000..3eefc8f --- /dev/null +++ b/partner_product_variants_shortcut/product.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Partner Product Variants Shortcut module for Odoo +# Copyright (C) 2014-2016 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 + + +# KEEP THIS IN OLD API for the moment +# Otherwise, you will have trouble in the pagination of kanban view and +# the counter for number of records in list view +# Bug found at the Barroux Abbey on 29/5/2015 +class ProductProduct(orm.Model): + _inherit = 'product.product' + + 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))) + res = super(ProductProduct, self).search( + cr, uid, args, offset=offset, limit=limit, order=order, + count=count, context=context) + return res diff --git a/partner_product_variants_shortcut/static/description/icon.png b/partner_product_variants_shortcut/static/description/icon.png new file mode 100644 index 0000000..6f980f2 Binary files /dev/null and b/partner_product_variants_shortcut/static/description/icon.png differ