partner_products_shortcut : Port to new API
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
# -*- encoding: utf-8 -*-
|
# -*- encoding: utf-8 -*-
|
||||||
##############################################################################
|
##############################################################################
|
||||||
#
|
#
|
||||||
# Partner Products Shortcut module for OpenERP
|
# Partner Products Shortcut module for Odoo
|
||||||
# Copyright (C) 2014 Akretion (http://www.akretion.com)
|
# Copyright (C) 2014-2015 Akretion (http://www.akretion.com)
|
||||||
# @author Alexis de Lattre <alexis.delattre@akretion.com>
|
# @author Alexis de Lattre <alexis.delattre@akretion.com>
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# This program is free software: you can redistribute it and/or modify
|
||||||
@@ -20,29 +20,23 @@
|
|||||||
#
|
#
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
from openerp.osv import orm, fields
|
from openerp import models, fields, api
|
||||||
|
|
||||||
|
|
||||||
class res_partner(orm.Model):
|
class ResPartner(models.Model):
|
||||||
_inherit = 'res.partner'
|
_inherit = 'res.partner'
|
||||||
|
|
||||||
def _product_supplied_count(
|
@api.one
|
||||||
self, cr, uid, ids, field_name, arg, context=None):
|
def _product_supplied_count(self):
|
||||||
res = dict(map(lambda x: (x, 0), ids))
|
|
||||||
try:
|
try:
|
||||||
for partner_id in ids:
|
sellers = self.env['product.supplierinfo'].search(
|
||||||
seller_ids = self.pool['product.supplierinfo'].search(
|
[('name', '=', self.id)])
|
||||||
cr, uid, [('name', '=', partner_id)], context=context)
|
ptemplates = self.env['product.template'].search(
|
||||||
pt_ids = self.pool['product.template'].search(
|
[('seller_ids', 'in', sellers.ids)])
|
||||||
cr, uid, [('seller_ids', 'in', seller_ids)],
|
self.product_supplied_count = len(ptemplates)
|
||||||
context=context)
|
|
||||||
res[partner_id] = len(pt_ids)
|
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
return res
|
|
||||||
|
|
||||||
_columns = {
|
product_supplied_count = fields.Integer(
|
||||||
'product_supplied_count': fields.function(
|
compute='_product_supplied_count', string="# of Products Supplied",
|
||||||
_product_supplied_count, string="# of Products Supplied",
|
readonly=True)
|
||||||
type='integer'),
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
# -*- encoding: utf-8 -*-
|
# -*- encoding: utf-8 -*-
|
||||||
##############################################################################
|
##############################################################################
|
||||||
#
|
#
|
||||||
# Partner Products Shortcut module for OpenERP
|
# Partner Products Shortcut module for Odoo
|
||||||
# Copyright (C) 2014 Akretion (http://www.akretion.com)
|
# Copyright (C) 2014-2015 Akretion (http://www.akretion.com)
|
||||||
# @author Alexis de Lattre <alexis.delattre@akretion.com>
|
# @author Alexis de Lattre <alexis.delattre@akretion.com>
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# This program is free software: you can redistribute it and/or modify
|
||||||
@@ -20,25 +20,22 @@
|
|||||||
#
|
#
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
from openerp.osv import orm
|
from openerp import models, api
|
||||||
|
|
||||||
|
|
||||||
class product_template(orm.Model):
|
class ProductTemplate(models.Model):
|
||||||
_inherit = 'product.template'
|
_inherit = 'product.template'
|
||||||
|
|
||||||
|
@api.model
|
||||||
def search(
|
def search(
|
||||||
self, cr, uid, args, offset=0, limit=None, order=None,
|
self, args, offset=0, limit=None, order=None, count=False):
|
||||||
context=None, count=False):
|
seller_id = self.env.context.get('search_default_seller_id')
|
||||||
if context is None:
|
|
||||||
context = {}
|
|
||||||
seller_id = context.get('search_default_seller_id')
|
|
||||||
if seller_id:
|
if seller_id:
|
||||||
seller_ids = self.pool['product.supplierinfo'].search(
|
sellers = self.env['product.supplierinfo'].search(
|
||||||
cr, uid, [('name', '=', seller_id)], context=context)
|
[('name', '=', seller_id)])
|
||||||
for argument in args:
|
for argument in args:
|
||||||
if isinstance(argument, list) and argument[0] == 'seller_ids':
|
if isinstance(argument, list) and argument[0] == 'seller_ids':
|
||||||
args.remove(argument)
|
args.remove(argument)
|
||||||
args.append((('seller_ids', 'in', seller_ids)))
|
args.append((('seller_ids', 'in', sellers.ids)))
|
||||||
return super(product_template, self).search(
|
return super(ProductTemplate, self).search(
|
||||||
cr, uid, args, offset=offset, limit=limit, order=order,
|
args, offset=offset, limit=limit, order=order, count=count)
|
||||||
context=context, count=count)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user