/
product.py
116 lines (103 loc) · 5 KB
/
product.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# -*- coding: utf-8 -*-
###########################################################################
# Module Writen to OpenERP, Open Source Management Solution
#
# Copyright (c) 2012 Vauxoo - http://www.vauxoo.com
# All Rights Reserved.
# info@vauxoo.com
############################################################################
# Coded by: Rodo (rodo@vauxoo.com),Moy (moylop260@vauxoo.com)
############################################################################
# Migrated to Odoo 8.0 by Acysos S.L. - http://www.acysos.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 ProductTemplate(models.Model):
_inherit = "product.template"
product_customer_code_ids = fields.One2many(
comodel_name='product.customer.code', inverse_name='product_id',
string='Customer Codes')
@api.model
def copy(self, default):
if not default:
default = {}
default['product_customer_code_ids'] = False
res = super(ProductTemplate, self).copy(default)
return res
def search(self, cr, uid, args, offset=0, limit=None, order=None,
context=None, count=False):
res = super(ProductTemplate, self).search(cr, uid, args, offset=offset,
limit=limit, order=order,
count=count)
operator = False
term = False
for arg in args:
if arg[0] == 'name':
operator = arg[1]
term = arg[2]
if not res and operator is not False and term is not False:
product_customer_code_obj = self.pool.get('product.customer.code')
product_ids = set(product_customer_code_obj.search(
cr, uid, [('product_code', operator, term)], limit=limit,
context=context))
if not limit or len(product_ids) < limit:
limit2 = (limit - len(product_ids)) if limit else False
product_ids.update(product_customer_code_obj.search(
cr, uid, [('product_name', operator, term)], limit=limit2,
context=context))
product_ids = list(product_ids)
product_datas = product_customer_code_obj.browse(cr, uid,
product_ids,
context)
prod_ids = []
for product_data in product_datas:
prod_ids.append(product_data.product_id.id)
res = prod_ids
return res
class ProductProduct(models.Model):
_inherit = "product.product"
def search(self, cr, uid, args, offset=0, limit=None, order=None,
context=None, count=False):
res = super(ProductProduct, self).search(cr, uid, args, offset=offset,
limit=limit, order=order,
context=context, count=count)
operator = False
term = False
for arg in args:
if arg[0] == 'name':
operator = arg[1]
term = arg[2]
if not res and operator is not False and term is not False:
cust_data_obj = self.pool.get('product.customer.code')
cust_ids = set(cust_data_obj.search(
cr, uid, [('product_code', operator, term)], limit=limit,
context=context))
if not limit or len(cust_ids) < limit:
limit2 = (limit - len(cust_ids)) if limit else False
cust_ids.update(cust_data_obj.search(
cr, uid, [('product_name', operator, term)], limit=limit2,
context=context))
cust_ids = list(cust_ids)
products_template = cust_data_obj.read(cr, uid, cust_ids,
['product_id'], context)
product_obj = self.pool.get('product.product')
for template in products_template:
prod_ids = product_obj.search(
cr, uid, [('product_tmpl_id', '=',
template['product_id'][0])], context=context)
for prod_id in prod_ids:
res.append(prod_id)
return res