diff --git a/partner_product_variants_shortcut/__init__.py b/partner_product_variants_shortcut/__init__.py deleted file mode 100644 index 428c04a..0000000 --- a/partner_product_variants_shortcut/__init__.py +++ /dev/null @@ -1,4 +0,0 @@ -# -*- coding: utf-8 -*- - -from . import product -from . import partner diff --git a/partner_product_variants_shortcut/__manifest__.py b/partner_product_variants_shortcut/__manifest__.py deleted file mode 100644 index 4a3188a..0000000 --- a/partner_product_variants_shortcut/__manifest__.py +++ /dev/null @@ -1,47 +0,0 @@ -# -*- 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': False, -} diff --git a/partner_product_variants_shortcut/partner.py b/partner_product_variants_shortcut/partner.py deleted file mode 100644 index 64b7a91..0000000 --- a/partner_product_variants_shortcut/partner.py +++ /dev/null @@ -1,42 +0,0 @@ -# -*- 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 deleted file mode 100644 index fe1977c..0000000 --- a/partner_product_variants_shortcut/partner_view.xml +++ /dev/null @@ -1,37 +0,0 @@ - - - - - - - - - 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 deleted file mode 100644 index 3eefc8f..0000000 --- a/partner_product_variants_shortcut/product.py +++ /dev/null @@ -1,49 +0,0 @@ -# -*- 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 deleted file mode 100644 index 6f980f2..0000000 Binary files a/partner_product_variants_shortcut/static/description/icon.png and /dev/null differ diff --git a/partner_products_shortcut/__init__.py b/partner_products_shortcut/__init__.py index 428c04a..61cf8b2 100644 --- a/partner_products_shortcut/__init__.py +++ b/partner_products_shortcut/__init__.py @@ -1,4 +1,3 @@ # -*- coding: utf-8 -*- -from . import product from . import partner diff --git a/partner_products_shortcut/__manifest__.py b/partner_products_shortcut/__manifest__.py index c392d0f..63a313d 100644 --- a/partner_products_shortcut/__manifest__.py +++ b/partner_products_shortcut/__manifest__.py @@ -1,39 +1,19 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# Partner Products 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 . -# -############################################################################## - +# © 2014-2016 Akretion (http://www.akretion.com) +# @author Alexis de Lattre +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { - 'name': 'Partner Products Shortcut', - 'version': '0.1', + 'name': 'Partner Product Shortcut', + 'version': '10.0.1.0.0', 'category': 'Contact Management', 'license': 'AGPL-3', 'summary': 'Adds a shortcut on partner form to the products supplied by this partner', 'description': """ -Partner Products Shortcut -========================= +Partner Product Shortcut +======================== -Adds a shortcut on supplier partner form to the products supplied by this partner. - -This module is an alternative to the module *partner_product_variants_shortcut* ; the only difference is that it displays the product view (product.template) instead of the product variants view (product.product). +Adds a shortcut on supplier partner form to the products supplied by this partner (display the product variants view). This module has been written by Alexis de Lattre from Akretion . @@ -41,7 +21,6 @@ This module has been written by Alexis de Lattre from Akretion 'author': 'Akretion', 'website': 'http://www.akretion.com', 'depends': ['product'], - 'conflicts': ['partner_product_variants_shortcut'], 'data': ['partner_view.xml'], - 'installable': False, + 'installable': True, } diff --git a/partner_products_shortcut/partner.py b/partner_products_shortcut/partner.py index b2ba92f..ea1645d 100644 --- a/partner_products_shortcut/partner.py +++ b/partner_products_shortcut/partner.py @@ -1,42 +1,48 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# Partner Products Shortcut module for Odoo -# Copyright (C) 2014-2015 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 . -# -############################################################################## +# © 2014-2016 Akretion (http://www.akretion.com) +# @author Alexis de Lattre +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from openerp import models, fields, api +from odoo import models, fields, api, _ +from openerp.exceptions import UserError class ResPartner(models.Model): _inherit = 'res.partner' - @api.one + @api.multi def _product_supplied_count(self): - try: - sellers = self.env['product.supplierinfo'].search( - [('name', '=', self.id)]) - ptemplates = self.env['product.template'].search( - [('seller_ids', 'in', sellers.ids)]) - self.product_supplied_count = len(ptemplates) - except: - pass + for partner in self: + count = False + try: + sellers = self.env['product.supplierinfo'].search( + [('name', '=', partner.id)]) + if sellers: + pproducts = self.env['product.product'].search( + [('seller_ids', 'in', sellers.ids)]) + count = len(pproducts) + except: + pass + partner.product_supplied_count = count product_supplied_count = fields.Integer( compute='_product_supplied_count', string="# of Products Supplied", readonly=True) + + @api.multi + def show_supplied_products(self): + self.ensure_one() + sellers = self.env['product.supplierinfo'].search( + [('name', '=', self.id)]) + if not sellers: + raise UserError(_( + "The supplier '%s' is not linked to any product") % self.name) + pproducts = self.env['product.product'].search( + [('seller_ids', 'in', sellers.ids)]) + action = self.env['ir.actions.act_window'].for_xml_id( + 'product', 'product_normal_action') + action.update({ + 'domain': "[('id', 'in', %s)]" % pproducts.ids, + }) + print "action=", action + return action diff --git a/partner_products_shortcut/partner_view.xml b/partner_products_shortcut/partner_view.xml index ca30182..8cd3fab 100644 --- a/partner_products_shortcut/partner_view.xml +++ b/partner_products_shortcut/partner_view.xml @@ -1,37 +1,27 @@ - - - - - - Products - product.template - tree,form,kanban - {'search_default_seller_id': active_id} - + - add.shortcut.to.products.partner.form + add.shortcut.to.product.variants.partner.form res.partner - - - + - - + diff --git a/partner_products_shortcut/product.py b/partner_products_shortcut/product.py deleted file mode 100644 index 92f0d05..0000000 --- a/partner_products_shortcut/product.py +++ /dev/null @@ -1,49 +0,0 @@ -# -*- coding: utf-8 -*- -############################################################################## -# -# Partner Products Shortcut module for Odoo -# Copyright (C) 2014-2015 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 ProductTemplate(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))) - res = super(ProductTemplate, self).search( - cr, uid, args, offset=offset, limit=limit, order=order, - count=count, context=context) - return res