Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by pedrobaeza
- Loading branch information
Showing
3 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
product_supplierinfo_for_customer/models/product_supplierinfo.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |