diff --git a/partner_products_shortcut/__init__.py b/partner_products_shortcut/__init__.py new file mode 100644 index 0000000..91fed54 --- /dev/null +++ b/partner_products_shortcut/__init__.py @@ -0,0 +1 @@ +from . import res_partner diff --git a/partner_products_shortcut/__manifest__.py b/partner_products_shortcut/__manifest__.py new file mode 100644 index 0000000..5b95ee4 --- /dev/null +++ b/partner_products_shortcut/__manifest__.py @@ -0,0 +1,27 @@ +# Copyright 2014-2024 Akretion (http://www.akretion.com) +# @author Alexis de Lattre +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + 'name': 'Partner Product Shortcut', + 'version': '16.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 Product Shortcut +======================== + +Adds a smartbutton on partner form to the products supplied by this partner. + +This is an alternative to the OCA module `partner_supplierinfo_smartbutton `_ which adds a smartbutton on partner form to links to the related product.supplierinfo (and not to product.template like in this module). + +This module has been written by Alexis de Lattre from Akretion +. + """, + 'author': 'Akretion', + 'website': 'https://github.com/akretion/odoo-usability', + 'depends': ['product'], + 'data': ['res_partner_view.xml'], + 'installable': True, +} diff --git a/partner_products_shortcut/res_partner.py b/partner_products_shortcut/res_partner.py new file mode 100644 index 0000000..16f2aa6 --- /dev/null +++ b/partner_products_shortcut/res_partner.py @@ -0,0 +1,38 @@ +# Copyright 2014-2024 Akretion (http://www.akretion.com) +# @author Alexis de Lattre +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import models, fields, _ + + +class ResPartner(models.Model): + _inherit = 'res.partner' + + def _product_supplied_count(self): + for partner in self: + count = 0 + sellers = self.env['product.supplierinfo'].search( + [('partner_id', '=', partner.id)]) + if sellers: + count = self.env['product.template'].search_count( + [('seller_ids', 'in', sellers.ids)]) + partner.product_supplied_count = count + + product_supplied_count = fields.Integer( + compute='_product_supplied_count', string="# of Products Supplied", + ) + + def show_supplied_products(self): + self.ensure_one() + sellers = self.env['product.supplierinfo'].search( + [('partner_id', '=', self.id)]) + ptemplates = self.env['product.template'].search( + [('seller_ids', 'in', sellers.ids)]) + action = { + 'name': _('Products'), + 'type': "ir.actions.act_window", + "res_model": "product.template", + "view_mode": 'tree,kanban,form', + 'domain': f"[('id', 'in', {ptemplates.ids})]", + } + return action diff --git a/partner_products_shortcut/res_partner_view.xml b/partner_products_shortcut/res_partner_view.xml new file mode 100644 index 0000000..09b4ddf --- /dev/null +++ b/partner_products_shortcut/res_partner_view.xml @@ -0,0 +1,27 @@ + + + + + + + add.shortcut.to.product.variants.partner.form + res.partner + + +
+ +
+
+
+ +
diff --git a/partner_products_shortcut/static/description/icon.png b/partner_products_shortcut/static/description/icon.png new file mode 100644 index 0000000..6f980f2 Binary files /dev/null and b/partner_products_shortcut/static/description/icon.png differ