Skip to content

Commit

Permalink
Merge PR #522 into 12.0
Browse files Browse the repository at this point in the history
Signed-off-by pedrobaeza
  • Loading branch information
OCA-git-bot committed Nov 14, 2019
2 parents 78bae31 + 3d7ec4e commit 1ef41e3
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 0 deletions.
1 change: 1 addition & 0 deletions product_supplierinfo_for_customer/models/__init__.py
@@ -1,5 +1,6 @@
from . import pricelist
from . import product_customerinfo
from . import product_supplierinfo
from . import product_product
from . import product_template
from . import res_partner
36 changes: 36 additions & 0 deletions product_supplierinfo_for_customer/models/product_product.py
Expand Up @@ -10,6 +10,42 @@
class ProductProduct(models.Model):
_inherit = 'product.product'

@api.multi
def name_get(self):
res = super(ProductProduct, self.with_context(customerinfo=True)).\
name_get()
return res

@api.model
def _name_search(self, name='', args=None, operator='ilike', limit=100,
name_get_uid=None):
res = super(ProductProduct, self)._name_search(
name, args=args, operator=operator, limit=limit,
name_get_uid=name_get_uid)
if not limit or len(res) >= limit:
limit = (limit - len(res)) if limit else False
if (not name and limit or not self._context.get('partner_id') or
len(res) >= limit):
return res
limit -= len(res)
customerinfo_ids = self.env['product.customerinfo']._search(
[('name', '=', self._context.get('partner_id')), '|',
('product_code', operator, name),
('product_name', operator, name)], limit=limit,
name_get_uid=name_get_uid)
if not customerinfo_ids:
return res
res_templates = self.browse(
[product_id for product_id, _name in res]
).mapped('product_tmpl_id')
product_tmpls = self.env['product.customerinfo'].browse(
customerinfo_ids).mapped('product_tmpl_id') - res_templates
product_ids = self._search(
[('product_tmpl_id', 'in', product_tmpls.ids)], limit=limit,
name_get_uid=name_get_uid)
res.extend(self.browse(product_ids).name_get())
return res

@api.multi
def _get_price_from_customerinfo(self, partner_id):
self.ensure_one()
Expand Down
38 changes: 38 additions & 0 deletions product_supplierinfo_for_customer/models/product_supplierinfo.py
@@ -0,0 +1,38 @@
# Copyright 2019 Eficent Business and IT Consulting Services S.L.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import api, models


class ProductSupplierInfo(models.Model):
_inherit = "product.supplierinfo"

@api.model
def search(self, args, offset=0, limit=None, order=None, count=False):
res = super(ProductSupplierInfo, self).search(
args, offset=offset, limit=limit, order=order, count=count)
if self.env.context.get('customerinfo') and \
self._name == 'product.supplierinfo':
limit2 = limit-len(res) if limit else limit
res2 = self.env['product.customerinfo'].search(
args, offset=offset, limit=limit2, order=order, count=count)
res2 = res2.read(
list(self.env['product.supplierinfo']._fields.keys()))
for result in res2:
res += self.env['product.supplierinfo'].new(result)
return res

@api.multi
def read(self, fields=None, load='_classic_read'):
if self.env.context.get('customerinfo') and \
self._name == 'product.supplierinfo':
has_ids = self.filtered(
lambda x: x.id in x._ids and isinstance(x.id, (int,)))
new_ids = self.filtered(
lambda x: x.id in x._ids and not isinstance(x.id, (int,)))
return super(ProductSupplierInfo, has_ids).read(
fields=fields, load=load) + [
{f: x[f] for f in x._fields if (
f in fields if fields else True)} for x in new_ids]
else:
return super(ProductSupplierInfo, self).read(
fields=fields, load=load)

0 comments on commit 1ef41e3

Please sign in to comment.