Port partner_products_shortcut to v10 (it is in fact a port of partner_product_variants_shortcut renamed to partner_products_shortcut, because I won't maintain 2 versions)

This commit is contained in:
Alexis de Lattre
2016-12-06 10:47:28 +01:00
parent 3eab0c9d7a
commit a9139b9430
11 changed files with 55 additions and 309 deletions

View File

@@ -1,4 +0,0 @@
# -*- coding: utf-8 -*-
from . import product
from . import partner

View File

@@ -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 <alexis.delattre@akretion.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': '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
<alexis.delattre@akretion.com>.
""",
'author': 'Akretion',
'website': 'http://www.akretion.com',
'depends': ['product'],
'conflicts': ['partner_products_shortcut'],
'data': ['partner_view.xml'],
'installable': False,
}

View File

@@ -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 <alexis.delattre@akretion.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 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)

View File

@@ -1,37 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2014-2016 Akretion (http://www.akretion.com/)
@author Alexis de Lattre <alexis.delattre@akretion.com>
The licence is in the file __openerp__.py
-->
<openerp>
<data>
<record id="partner_products_action" model="ir.actions.act_window">
<field name="name">Product Variants</field>
<field name="res_model">product.product</field>
<field name="view_mode">tree,form,kanban</field>
<field name="context">{'search_default_seller_id': active_id}</field>
</record>
<record id="view_partner_form" model="ir.ui.view">
<field name="name">add.shortcut.to.product.variants.partner.form</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="arch" type="xml">
<xpath expr="//div[@name='buttons']" position="inside">
<button class="oe_inline oe_stat_button" type="action"
name="%(partner_product_variants_shortcut.partner_products_action)d"
icon="fa-truck"
attrs="{'invisible': [('supplier', '=', False)]}">
<field string="Products Supplied" name="product_supplied_count"
widget="statinfo"/>
</button>
</xpath>
</field>
</record>
</data>
</openerp>

View File

@@ -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 <alexis.delattre@akretion.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
# 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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

View File

@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from . import product
from . import partner from . import partner

View File

@@ -1,39 +1,19 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
############################################################################## # © 2014-2016 Akretion (http://www.akretion.com)
# # @author Alexis de Lattre <alexis.delattre@akretion.com>
# Partner Products Shortcut module for Odoo # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
# Copyright (C) 2014-2016 Akretion (http://www.akretion.com)
# @author Alexis de Lattre <alexis.delattre@akretion.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': 'Partner Products Shortcut', 'name': 'Partner Product Shortcut',
'version': '0.1', 'version': '10.0.1.0.0',
'category': 'Contact Management', 'category': 'Contact Management',
'license': 'AGPL-3', 'license': 'AGPL-3',
'summary': 'Adds a shortcut on partner form to the products supplied by this partner', 'summary': 'Adds a shortcut on partner form to the products supplied by this partner',
'description': """ 'description': """
Partner Products Shortcut Partner Product Shortcut
========================= ========================
Adds a shortcut on supplier partner form to the products supplied by this partner. 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_product_variants_shortcut* ; the only difference is that it displays the product view (product.template) instead of the product variants view (product.product).
This module has been written by Alexis de Lattre from Akretion This module has been written by Alexis de Lattre from Akretion
<alexis.delattre@akretion.com>. <alexis.delattre@akretion.com>.
@@ -41,7 +21,6 @@ This module has been written by Alexis de Lattre from Akretion
'author': 'Akretion', 'author': 'Akretion',
'website': 'http://www.akretion.com', 'website': 'http://www.akretion.com',
'depends': ['product'], 'depends': ['product'],
'conflicts': ['partner_product_variants_shortcut'],
'data': ['partner_view.xml'], 'data': ['partner_view.xml'],
'installable': False, 'installable': True,
} }

View File

@@ -1,42 +1,48 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
############################################################################## # © 2014-2016 Akretion (http://www.akretion.com)
# # @author Alexis de Lattre <alexis.delattre@akretion.com>
# Partner Products Shortcut module for Odoo # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
# Copyright (C) 2014-2015 Akretion (http://www.akretion.com)
# @author Alexis de Lattre <alexis.delattre@akretion.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 import models, fields, api from odoo import models, fields, api, _
from openerp.exceptions import UserError
class ResPartner(models.Model): class ResPartner(models.Model):
_inherit = 'res.partner' _inherit = 'res.partner'
@api.one @api.multi
def _product_supplied_count(self): def _product_supplied_count(self):
try: for partner in self:
sellers = self.env['product.supplierinfo'].search( count = False
[('name', '=', self.id)]) try:
ptemplates = self.env['product.template'].search( sellers = self.env['product.supplierinfo'].search(
[('seller_ids', 'in', sellers.ids)]) [('name', '=', partner.id)])
self.product_supplied_count = len(ptemplates) if sellers:
except: pproducts = self.env['product.product'].search(
pass [('seller_ids', 'in', sellers.ids)])
count = len(pproducts)
except:
pass
partner.product_supplied_count = count
product_supplied_count = fields.Integer( product_supplied_count = fields.Integer(
compute='_product_supplied_count', string="# of Products Supplied", compute='_product_supplied_count', string="# of Products Supplied",
readonly=True) 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

View File

@@ -1,37 +1,27 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<!-- <!--
Copyright (C) 2014 Akretion (http://www.akretion.com/) Copyright (C) 2014-2016 Akretion (http://www.akretion.com/)
@author Alexis de Lattre <alexis.delattre@akretion.com> @author Alexis de Lattre <alexis.delattre@akretion.com>
The licence is in the file __openerp__.py License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
--> -->
<openerp> <odoo>
<data>
<record id="partner_products_action" model="ir.actions.act_window">
<field name="name">Products</field>
<field name="res_model">product.template</field>
<field name="view_mode">tree,form,kanban</field>
<field name="context">{'search_default_seller_id': active_id}</field>
</record>
<record id="view_partner_form" model="ir.ui.view"> <record id="view_partner_form" model="ir.ui.view">
<field name="name">add.shortcut.to.products.partner.form</field> <field name="name">add.shortcut.to.product.variants.partner.form</field>
<field name="model">res.partner</field> <field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form"/> <field name="inherit_id" ref="base.view_partner_form"/>
<field name="arch" type="xml"> <field name="arch" type="xml">
<xpath expr="//div[@name='buttons']" position="inside"> <div name="button_box" position="inside">
<button class="oe_inline oe_stat_button" type="action" <button class="oe_inline oe_stat_button" type="object"
name="%(partner_products_shortcut.partner_products_action)d" name="show_supplied_products"
icon="fa-truck" icon="fa-truck"
attrs="{'invisible': [('supplier', '=', False)]}"> attrs="{'invisible': [('supplier', '=', False)]}">
<field string="Products Supplied" name="product_supplied_count" <field string="Products Supplied" name="product_supplied_count"
widget="statinfo"/> widget="statinfo"/>
</button> </button>
</xpath> </div>
</field> </field>
</record> </record>
</data> </odoo>
</openerp>

View File

@@ -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 <alexis.delattre@akretion.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
# 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