Add module partner_product_variants_shortcut

This commit is contained in:
Alexis de Lattre
2016-02-27 00:25:35 +01:00
parent 14518c7f9f
commit 518628ec8c
6 changed files with 179 additions and 0 deletions

View File

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

View File

@@ -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 <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': True,
}

View File

@@ -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 <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

@@ -0,0 +1,37 @@
<?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

@@ -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 <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.

After

Width:  |  Height:  |  Size: 18 KiB