Add module partner_products_shortcut.
This commit is contained in:
24
partner_products_shortcut/__init__.py
Normal file
24
partner_products_shortcut/__init__.py
Normal file
@@ -0,0 +1,24 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# Partner Products Shortcut module for OpenERP
|
||||
# Copyright (C) 2014 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 . import product
|
||||
from . import partner
|
||||
45
partner_products_shortcut/__openerp__.py
Normal file
45
partner_products_shortcut/__openerp__.py
Normal file
@@ -0,0 +1,45 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# Partner Products Shortcut module for OpenERP
|
||||
# Copyright (C) 2014 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',
|
||||
'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 Products Shortcut
|
||||
=========================
|
||||
|
||||
Adds a shortcut on supplier partner form to the products supplied by this partner.
|
||||
|
||||
Please contact Alexis de Lattre from Akretion <alexis.delattre@akretion.com> for any help or question about this module.
|
||||
""",
|
||||
'author': 'Akretion',
|
||||
'website': 'http://www.akretion.com',
|
||||
'depends': ['product'],
|
||||
'data': [
|
||||
'partner_view.xml',
|
||||
],
|
||||
'active': False,
|
||||
}
|
||||
48
partner_products_shortcut/partner.py
Normal file
48
partner_products_shortcut/partner.py
Normal file
@@ -0,0 +1,48 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# Partner Products Shortcut module for OpenERP
|
||||
# Copyright (C) 2014 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, fields
|
||||
|
||||
|
||||
class res_partner(orm.Model):
|
||||
_inherit = 'res.partner'
|
||||
|
||||
def _product_supplied_count(
|
||||
self, cr, uid, ids, field_name, arg, context=None):
|
||||
res = dict(map(lambda x: (x, 0), ids))
|
||||
try:
|
||||
for partner_id in ids:
|
||||
seller_ids = self.pool['product.supplierinfo'].search(
|
||||
cr, uid, [('name', '=', partner_id)], context=context)
|
||||
pt_ids = self.pool['product.template'].search(
|
||||
cr, uid, [('seller_ids', 'in', seller_ids)],
|
||||
context=context)
|
||||
res[partner_id] = len(pt_ids)
|
||||
except:
|
||||
pass
|
||||
return res
|
||||
|
||||
_columns = {
|
||||
'product_supplied_count': fields.function(
|
||||
_product_supplied_count, string="# of Products Supplied",
|
||||
type='integer'),
|
||||
}
|
||||
37
partner_products_shortcut/partner_view.xml
Normal file
37
partner_products_shortcut/partner_view.xml
Normal file
@@ -0,0 +1,37 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<!--
|
||||
Copyright (C) 2014 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">Products</field>
|
||||
<field name="res_model">product.template</field>
|
||||
<field name="view_mode">kanban,tree,form</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.products.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_products_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>
|
||||
44
partner_products_shortcut/product.py
Normal file
44
partner_products_shortcut/product.py
Normal file
@@ -0,0 +1,44 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# Partner Products Shortcut module for OpenERP
|
||||
# Copyright (C) 2014 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
|
||||
|
||||
|
||||
class product_template(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)))
|
||||
return super(product_template, self).search(
|
||||
cr, uid, args, offset=offset, limit=limit, order=order,
|
||||
context=context, count=count)
|
||||
Reference in New Issue
Block a user