232.2.1
by Quentin THEURET
UF-374 [ADD] Added product_list module |
1 |
# -*- coding: utf-8 -*-
|
2 |
##############################################################################
|
|
3 |
#
|
|
4 |
# OpenERP, Open Source Management Solution
|
|
2560.1.1
by Quentin THEURET
US-417 [IMP] Imporve code style |
5 |
# Copyright (C) 2011 TeMPO Consulting, MSF
|
232.2.1
by Quentin THEURET
UF-374 [ADD] Added product_list module |
6 |
#
|
7 |
# This program is free software: you can redistribute it and/or modify
|
|
8 |
# it under the terms of the GNU Affero General Public License as
|
|
9 |
# published by the Free Software Foundation, either version 3 of the
|
|
10 |
# License, or (at your option) any later version.
|
|
11 |
#
|
|
12 |
# This program is distributed in the hope that it will be useful,
|
|
13 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15 |
# GNU Affero General Public License for more details.
|
|
16 |
#
|
|
17 |
# You should have received a copy of the GNU Affero General Public License
|
|
18 |
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
19 |
#
|
|
20 |
##############################################################################
|
|
21 |
||
22 |
from osv import osv, fields |
|
2382.1.1
by Quentin THEURET
US-63 [FIX] Disallow deletion of Unifield internal objects (Nomenclature, product, UoM…) |
23 |
from tools.translate import _ |
232.2.1
by Quentin THEURET
UF-374 [ADD] Added product_list module |
24 |
|
25 |
import time |
|
1249.10.36
by matthieu.choplin at msf
[uf-1544] yml tests |
26 |
import logging |
232.2.2
by Quentin THEURET
IF-374 [ADD] Added wizard for import/export products in products lists |
27 |
|
1249.10.34
by matthieu.choplin at msf
[uf-1544] come back to revno 1268 with the default_code and the international_status required in the view but not in the python code (to pass the data and the yml tests) |
28 |
|
232.2.1
by Quentin THEURET
UF-374 [ADD] Added product_list module |
29 |
class product_list(osv.osv): |
30 |
_name = 'product.list' |
|
31 |
_description = 'Products list' |
|
2560.1.1
by Quentin THEURET
US-417 [IMP] Imporve code style |
32 |
|
707
by jf
[FIX] Default values |
33 |
def _get_nb_products(self, cr, uid, ids, field_name, arg, context=None): |
232.2.1
by Quentin THEURET
UF-374 [ADD] Added product_list module |
34 |
'''
|
35 |
Returns the number of products on the list
|
|
36 |
'''
|
|
37 |
res = {} |
|
2560.1.1
by Quentin THEURET
US-417 [IMP] Imporve code style |
38 |
|
232.2.1
by Quentin THEURET
UF-374 [ADD] Added product_list module |
39 |
for list in self.browse(cr, uid, ids, context=context): |
40 |
res[list.id] = len(list.product_ids) |
|
2560.1.1
by Quentin THEURET
US-417 [IMP] Imporve code style |
41 |
|
232.2.1
by Quentin THEURET
UF-374 [ADD] Added product_list module |
42 |
return res |
2560.1.1
by Quentin THEURET
US-417 [IMP] Imporve code style |
43 |
|
707
by jf
[FIX] Default values |
44 |
def write(self, cr, uid, ids, vals, context=None): |
232.2.1
by Quentin THEURET
UF-374 [ADD] Added product_list module |
45 |
'''
|
46 |
Adds update date and user information
|
|
47 |
'''
|
|
2560.1.1
by Quentin THEURET
US-417 [IMP] Imporve code style |
48 |
vals.update({ |
2594
by jf
US-417 [FIX] Product sublist: check product is in parent list + code style |
49 |
'reviewer_id': uid, |
2560.1.1
by Quentin THEURET
US-417 [IMP] Imporve code style |
50 |
'last_update_date': time.strftime('%Y-%m-%d'), |
51 |
})
|
|
52 |
||
2617.1.1
by Quentin THEURET
US-572 [FIX] On product lists: |
53 |
if vals.get('type') == 'list': |
54 |
vals['parent_id'] = False |
|
55 |
||
2560.1.1
by Quentin THEURET
US-417 [IMP] Imporve code style |
56 |
return super(product_list, self).\ |
57 |
write(cr, uid, ids, vals, context=context) |
|
58 |
||
707
by jf
[FIX] Default values |
59 |
def copy(self, cr, uid, id, default=None, context=None): |
232.2.3
by Quentin THEURET
UF-374 [ADD] Added unit tests for product_list module |
60 |
'''
|
61 |
Remove the last update date and the reviewer on the new list
|
|
62 |
'''
|
|
63 |
if not context: |
|
64 |
context = {} |
|
459.2.1
by Quentin THEURET
UF-746 [FIX] Add uniqueness of name of products lists |
65 |
|
66 |
name = self.browse(cr, uid, id, context=context).name + ' (copy)' |
|
2560.1.1
by Quentin THEURET
US-417 [IMP] Imporve code style |
67 |
|
68 |
return super(product_list, self).copy(cr, uid, id, { |
|
69 |
'last_update_date': False, |
|
70 |
'name': name, |
|
71 |
'reviewer_id': False, |
|
72 |
}, context=context) |
|
73 |
||
232.2.1
by Quentin THEURET
UF-374 [ADD] Added product_list module |
74 |
_columns = { |
2560.1.1
by Quentin THEURET
US-417 [IMP] Imporve code style |
75 |
'name': fields.char( |
76 |
size=128, |
|
77 |
string='Name', |
|
78 |
required=True, |
|
79 |
),
|
|
80 |
'ref': fields.char( |
|
81 |
size=128, |
|
82 |
string='Ref.', |
|
83 |
),
|
|
84 |
'type': fields.selection( |
|
85 |
selection=[ |
|
86 |
('list', 'List'), |
|
87 |
('sublist', 'Sublist'), |
|
88 |
],
|
|
89 |
string='Type', |
|
90 |
required=True, |
|
91 |
),
|
|
2703.5.1
by Quentin THEURET
US-485 [IMP] Add a new field 'Creator' on the product list document - New patch to set the existing product list creator to 'Project' |
92 |
'creator': fields.selection( |
93 |
selection=[ |
|
94 |
('hq', 'HQ'), |
|
95 |
('coordo', 'Coordination'), |
|
96 |
('project', 'Project'), |
|
2703.5.2
by Quentin THEURET
US-485 [IMP] Add a new 'Temporary' option for product list creator field |
97 |
('temp', 'Temporary'), |
2703.5.1
by Quentin THEURET
US-485 [IMP] Add a new field 'Creator' on the product list document - New patch to set the existing product list creator to 'Project' |
98 |
],
|
99 |
string='Creator', |
|
100 |
required=True, |
|
101 |
),
|
|
2560.1.1
by Quentin THEURET
US-417 [IMP] Imporve code style |
102 |
'description': fields.char( |
103 |
size=256, |
|
104 |
string='Description', |
|
105 |
),
|
|
106 |
'creation_date': fields.date( |
|
107 |
string='Creation date', |
|
108 |
readonly=True, |
|
109 |
),
|
|
110 |
'last_update_date': fields.date( |
|
111 |
string='Last update date', |
|
112 |
readonly=True, |
|
113 |
),
|
|
114 |
'standard_list_ok': fields.boolean( |
|
115 |
string='Standard List', |
|
116 |
),
|
|
117 |
'order_list_print_ok': fields.boolean( |
|
118 |
string='Order list print', |
|
119 |
),
|
|
120 |
'reviewer_id': fields.many2one( |
|
121 |
'res.users', |
|
122 |
string='Reviewed by', |
|
123 |
readonly=True, |
|
124 |
),
|
|
125 |
'parent_id': fields.many2one( |
|
126 |
'product.list', |
|
127 |
string='Parent list', |
|
128 |
),
|
|
129 |
'warehouse_id': fields.many2one( |
|
130 |
'stock.warehouse', |
|
131 |
string='Warehouse', |
|
132 |
),
|
|
133 |
'location_id': fields.many2one( |
|
134 |
'stock.location', |
|
135 |
string='Stock Location', |
|
136 |
),
|
|
137 |
'product_ids': fields.one2many( |
|
138 |
'product.list.line', |
|
139 |
'list_id', |
|
140 |
string='Products', |
|
141 |
),
|
|
142 |
'old_product_ids': fields.one2many( |
|
143 |
'old.product.list.line', |
|
144 |
'list_id', |
|
145 |
string='Old Products', |
|
146 |
),
|
|
147 |
'nb_products': fields.function( |
|
148 |
_get_nb_products, |
|
149 |
method=True, |
|
150 |
type='integer', |
|
151 |
string='# of products', |
|
152 |
),
|
|
153 |
||
232.2.1
by Quentin THEURET
UF-374 [ADD] Added product_list module |
154 |
}
|
2560.1.1
by Quentin THEURET
US-417 [IMP] Imporve code style |
155 |
|
232.2.1
by Quentin THEURET
UF-374 [ADD] Added product_list module |
156 |
_defaults = { |
157 |
'creation_date': lambda *a: time.strftime('%Y-%m-%d'), |
|
2703.5.3
by Quentin THEURET
US-485 [IMP] Put 'Temporary' as default value for creator field on new product lists |
158 |
'creator': lambda *a: 'temp', |
232.2.1
by Quentin THEURET
UF-374 [ADD] Added product_list module |
159 |
}
|
426.11.3
by Quentin THEURET
UF-576 [ADD] Added a replace feature on product list import |
160 |
|
459.2.1
by Quentin THEURET
UF-746 [FIX] Add uniqueness of name of products lists |
161 |
_sql_constraints = [ |
162 |
('name_uniq', 'unique (name)', 'A list or sublist with the same name already exists in the system!') |
|
163 |
]
|
|
164 |
||
2617.1.1
by Quentin THEURET
US-572 [FIX] On product lists: |
165 |
def change_parent_list(self, cr, uid, ids, list_id, product_ids, context=None): |
166 |
'''
|
|
167 |
Check if all products are in the parent list
|
|
168 |
'''
|
|
169 |
if not list_id: |
|
170 |
return {} |
|
171 |
||
172 |
parent_product_ids = [] |
|
173 |
list_brw = self.browse(cr, uid, list_id, context=context) |
|
174 |
for list_line in list_brw.product_ids: |
|
175 |
parent_product_ids.append(list_line.name.id) |
|
176 |
||
177 |
for product in product_ids: |
|
178 |
if product[2]['name'][0] not in parent_product_ids: |
|
179 |
return { |
|
180 |
'value': { |
|
181 |
'parent_id': False, |
|
182 |
},
|
|
183 |
'warning': { |
|
184 |
'title': _('Not consistent parent list'), |
|
185 |
'message': _('The selected parent list is not consistent with the products in the list. Please select another parent list or remove the products of the list that are not in the selected parent list before select the parent list.'), |
|
186 |
}
|
|
187 |
}
|
|
188 |
||
189 |
return {} |
|
190 |
||
191 |
||
2560.1.5
by Quentin THEURET
US-417 [IMP] Disallow possiblity to select a parent list if there is products on the current product list |
192 |
def change_product_line(self, cr, uid, ids, product_ids, context=None): |
426.11.3
by Quentin THEURET
UF-576 [ADD] Added a replace feature on product list import |
193 |
'''
|
194 |
Refresh the old product list
|
|
195 |
'''
|
|
196 |
res = {} |
|
197 |
old_products = [] |
|
198 |
for list in self.browse(cr, uid, ids, context=context): |
|
199 |
for old_line in list.old_product_ids: |
|
200 |
old_products.append(old_line.id) |
|
201 |
||
202 |
res.update({'old_product_ids': old_products}) |
|
203 |
||
2560.1.5
by Quentin THEURET
US-417 [IMP] Disallow possiblity to select a parent list if there is products on the current product list |
204 |
if product_ids: |
205 |
res.update({'nb_products': len(product_ids[0][2])}) |
|
206 |
else: |
|
207 |
res.update({'nb_products': 0}) |
|
208 |
||
426.11.3
by Quentin THEURET
UF-576 [ADD] Added a replace feature on product list import |
209 |
return {'value': res} |
459.4.1
by Quentin THEURET
UF-747 [IMP] Added a wizard to have the possibility to select multiple products |
210 |
|
707
by jf
[FIX] Default values |
211 |
def call_add_products(self, cr, uid, ids, context=None): |
459.4.1
by Quentin THEURET
UF-747 [IMP] Added a wizard to have the possibility to select multiple products |
212 |
'''
|
213 |
Call the add multiple products wizard
|
|
214 |
'''
|
|
215 |
if not context: |
|
216 |
context = {} |
|
217 |
||
218 |
if isinstance(ids, (int, long)): |
|
219 |
ids = [ids] |
|
220 |
||
221 |
for list in self.browse(cr, uid, ids, context=context): |
|
2560.1.1
by Quentin THEURET
US-417 [IMP] Imporve code style |
222 |
wiz_id = self.pool.get('product.list.add.products').\ |
223 |
create(cr, uid, {'list_id': list.id}, context=context) |
|
224 |
||
225 |
return { |
|
226 |
'type': 'ir.actions.act_window', |
|
227 |
'res_model': 'product.list.add.products', |
|
228 |
'res_id': wiz_id, |
|
229 |
'view_type': 'form', |
|
230 |
'view_mode': 'form', |
|
231 |
'target': 'new', |
|
232 |
'context': context, |
|
233 |
}
|
|
459.4.1
by Quentin THEURET
UF-747 [IMP] Added a wizard to have the possibility to select multiple products |
234 |
|
232.2.1
by Quentin THEURET
UF-374 [ADD] Added product_list module |
235 |
product_list() |
236 |
||
232.2.2
by Quentin THEURET
IF-374 [ADD] Added wizard for import/export products in products lists |
237 |
|
238 |
class product_list_line(osv.osv): |
|
239 |
_name = 'product.list.line' |
|
240 |
_description = 'Line of product list' |
|
1249.8.1
by Quentin THEURET
UF-1498 [IFX] Sort product list line by default code of the product |
241 |
_order = 'ref' |
1249.8.3
by Quentin THEURET
UF-1498 [FIX] Fix the store attributes of some 'default_code' related fields to re-compute these value each time the default_code of the product is change |
242 |
|
243 |
def _get_product(self, cr, uid, ids, context=None): |
|
2560.1.1
by Quentin THEURET
US-417 [IMP] Imporve code style |
244 |
return self.pool.get('product.list.line').\ |
245 |
search(cr, uid, [('name', 'in', ids)], context=context) |
|
246 |
||
232.2.2
by Quentin THEURET
IF-374 [ADD] Added wizard for import/export products in products lists |
247 |
_columns = { |
2560.1.1
by Quentin THEURET
US-417 [IMP] Imporve code style |
248 |
'name': fields.many2one( |
249 |
'product.product', |
|
250 |
string='Product Description', |
|
251 |
required=True, |
|
252 |
),
|
|
253 |
'list_id': fields.many2one( |
|
254 |
'product.list', |
|
255 |
string='List', |
|
256 |
ondelete='cascade', |
|
257 |
),
|
|
258 |
'ref': fields.related( |
|
259 |
'name', |
|
260 |
'default_code', |
|
261 |
string='Product Code', |
|
262 |
readonly=True, |
|
263 |
type='char', |
|
264 |
size=64, |
|
265 |
store={ |
|
266 |
'product.product': ( |
|
267 |
_get_product, ['default_code'], 10, |
|
268 |
),
|
|
269 |
'product.list.line': ( |
|
270 |
lambda self, cr, uid, ids, c=None: ids, ['name'], 20, |
|
271 |
),
|
|
272 |
},
|
|
273 |
),
|
|
274 |
'comment': fields.char( |
|
275 |
size=256, |
|
276 |
string='Comment', |
|
277 |
),
|
|
232.2.2
by Quentin THEURET
IF-374 [ADD] Added wizard for import/export products in products lists |
278 |
}
|
279 |
||
707
by jf
[FIX] Default values |
280 |
def unlink(self, cr, uid, ids, context=None): |
426.11.3
by Quentin THEURET
UF-576 [ADD] Added a replace feature on product list import |
281 |
'''
|
282 |
Create old product list line on product list line deletion
|
|
283 |
'''
|
|
2560.1.1
by Quentin THEURET
US-417 [IMP] Imporve code style |
284 |
opll = self.pool.get('old.product.list.line') |
285 |
||
426.11.3
by Quentin THEURET
UF-576 [ADD] Added a replace feature on product list import |
286 |
if not context: |
287 |
context = {} |
|
288 |
||
2560.1.1
by Quentin THEURET
US-417 [IMP] Imporve code style |
289 |
if isinstance(ids, (int, long)): |
426.11.3
by Quentin THEURET
UF-576 [ADD] Added a replace feature on product list import |
290 |
ids = [ids] |
291 |
||
292 |
if not context.get('import_error', False): |
|
293 |
for line in self.read(cr, uid, ids, context=context): |
|
2560.1.1
by Quentin THEURET
US-417 [IMP] Imporve code style |
294 |
opll.create(cr, uid, { |
295 |
'removal_date': time.strftime('%Y-%m-%d'), |
|
296 |
'comment': 'comment' in line and line['comment'] or '', |
|
297 |
'name': line['name'][0], |
|
298 |
'list_id': line['list_id'][0], |
|
299 |
}, context=context) |
|
300 |
||
301 |
return super(product_list_line, self).\ |
|
302 |
unlink(cr, uid, ids, context=context) |
|
426.11.3
by Quentin THEURET
UF-576 [ADD] Added a replace feature on product list import |
303 |
|
232.2.2
by Quentin THEURET
IF-374 [ADD] Added wizard for import/export products in products lists |
304 |
product_list_line() |
305 |
||
374.3.1
by Quentin THEURET
UF-585 [IMP] Filtered products which are in parent list in product list |
306 |
|
426.11.3
by Quentin THEURET
UF-576 [ADD] Added a replace feature on product list import |
307 |
class old_product_list_line(osv.osv): |
308 |
_name = 'old.product.list.line' |
|
309 |
_inherit = 'product.list.line' |
|
310 |
_order = 'removal_date' |
|
311 |
||
1349.7.1
by Quentin THEURET
Fix product_list unit tests warning messages |
312 |
def _get_product(self, cr, uid, ids, context=None): |
2560.1.1
by Quentin THEURET
US-417 [IMP] Imporve code style |
313 |
opll = self.pool.get('old.product.list.line') |
314 |
return opll.search(cr, uid, [('name', 'in', ids)], context=context) |
|
1349.7.1
by Quentin THEURET
Fix product_list unit tests warning messages |
315 |
|
426.11.3
by Quentin THEURET
UF-576 [ADD] Added a replace feature on product list import |
316 |
_columns = { |
2560.1.1
by Quentin THEURET
US-417 [IMP] Imporve code style |
317 |
'removal_date': fields.date( |
318 |
string='Removal date', |
|
319 |
readonly=True, |
|
320 |
),
|
|
321 |
'ref': fields.related( |
|
322 |
'name', |
|
323 |
'default_code', |
|
324 |
string='Product Code', |
|
325 |
readonly=True, |
|
326 |
type='char', |
|
327 |
size=64, |
|
328 |
store={ |
|
329 |
'product.product': ( |
|
330 |
_get_product, ['default_code'], 10, |
|
331 |
),
|
|
332 |
'old.product.list.line': ( |
|
333 |
lambda self, cr, uid, ids, c=None: ids, ['name'], 20, |
|
334 |
),
|
|
335 |
},
|
|
336 |
),
|
|
426.11.3
by Quentin THEURET
UF-576 [ADD] Added a replace feature on product list import |
337 |
}
|
338 |
||
339 |
_defaults = { |
|
340 |
'removal_date': lambda *a: time.strftime('%Y-%m-%d'), |
|
341 |
}
|
|
342 |
||
343 |
old_product_list_line() |
|
344 |
||
345 |
||
374.3.1
by Quentin THEURET
UF-585 [IMP] Filtered products which are in parent list in product list |
346 |
class product_product(osv.osv): |
347 |
_name = 'product.product' |
|
348 |
_inherit = 'product.product' |
|
349 |
||
2382.1.1
by Quentin THEURET
US-63 [FIX] Disallow deletion of Unifield internal objects (Nomenclature, product, UoM…) |
350 |
def unlink(self, cr, uid, ids, context=None): |
351 |
"""
|
|
352 |
Check if the unlinked product is not the 'To be defined' product
|
|
353 |
"""
|
|
354 |
try: |
|
355 |
prd_tbd = self.pool.get('ir.model.data').get_object_reference( |
|
356 |
cr, uid, 'msf_doc_import', 'product_tbd')[1] |
|
357 |
if prd_tbd in ids: |
|
358 |
raise osv.except_osv( |
|
359 |
_('Error'), |
|
360 |
_("""The product 'To be defined' is an Unifield internal |
|
361 |
product and can't be deleted"""), |
|
362 |
)
|
|
363 |
except ValueError: |
|
364 |
pass
|
|
365 |
||
366 |
return super(product_product, self).unlink(cr, uid, ids, context=context) |
|
374.3.1
by Quentin THEURET
UF-585 [IMP] Filtered products which are in parent list in product list |
367 |
|
707
by jf
[FIX] Default values |
368 |
def _get_list_sublist(self, cr, uid, ids, field_name, arg, context=None): |
374.3.1
by Quentin THEURET
UF-585 [IMP] Filtered products which are in parent list in product list |
369 |
'''
|
370 |
Returns all lists/sublists where the product is in
|
|
371 |
'''
|
|
2560.1.1
by Quentin THEURET
US-417 [IMP] Imporve code style |
372 |
pll_obj = self.pool.get('product.list.line') |
373 |
||
374.3.1
by Quentin THEURET
UF-585 [IMP] Filtered products which are in parent list in product list |
374 |
if not context: |
375 |
context = {} |
|
2560.1.1
by Quentin THEURET
US-417 [IMP] Imporve code style |
376 |
|
377 |
if isinstance(ids, (long, int)): |
|
374.3.1
by Quentin THEURET
UF-585 [IMP] Filtered products which are in parent list in product list |
378 |
ids = [ids] |
2560.1.1
by Quentin THEURET
US-417 [IMP] Imporve code style |
379 |
|
374.3.1
by Quentin THEURET
UF-585 [IMP] Filtered products which are in parent list in product list |
380 |
res = {} |
2560.1.1
by Quentin THEURET
US-417 [IMP] Imporve code style |
381 |
|
374.3.1
by Quentin THEURET
UF-585 [IMP] Filtered products which are in parent list in product list |
382 |
for product in self.browse(cr, uid, ids, context=context): |
383 |
res[product.id] = [] |
|
2560.1.1
by Quentin THEURET
US-417 [IMP] Imporve code style |
384 |
line_ids = pll_obj.search(cr, uid, [ |
385 |
('name', '=', product.id), |
|
386 |
], context=context) |
|
387 |
for line in pll_obj.browse(cr, uid, line_ids, context=context): |
|
374.3.1
by Quentin THEURET
UF-585 [IMP] Filtered products which are in parent list in product list |
388 |
if line.list_id and line.list_id.id not in res[product.id]: |
389 |
res[product.id].append(line.list_id.id) |
|
2560.1.1
by Quentin THEURET
US-417 [IMP] Imporve code style |
390 |
|
374.3.1
by Quentin THEURET
UF-585 [IMP] Filtered products which are in parent list in product list |
391 |
return res |
2560.1.1
by Quentin THEURET
US-417 [IMP] Imporve code style |
392 |
|
707
by jf
[FIX] Default values |
393 |
def _search_list_sublist(self, cr, uid, obj, name, args, context=None): |
374.3.1
by Quentin THEURET
UF-585 [IMP] Filtered products which are in parent list in product list |
394 |
'''
|
395 |
Filter the search according to the args parameter
|
|
396 |
'''
|
|
2560.1.1
by Quentin THEURET
US-417 [IMP] Imporve code style |
397 |
pl_obj = self.pool.get('product.list') |
398 |
||
374.3.1
by Quentin THEURET
UF-585 [IMP] Filtered products which are in parent list in product list |
399 |
if not context: |
400 |
context = {} |
|
2560.1.1
by Quentin THEURET
US-417 [IMP] Imporve code style |
401 |
|
374.3.1
by Quentin THEURET
UF-585 [IMP] Filtered products which are in parent list in product list |
402 |
ids = [] |
2560.1.1
by Quentin THEURET
US-417 [IMP] Imporve code style |
403 |
|
374.3.1
by Quentin THEURET
UF-585 [IMP] Filtered products which are in parent list in product list |
404 |
for arg in args: |
405 |
if arg[0] == 'list_ids' and arg[1] == '=' and arg[2]: |
|
2560.1.1
by Quentin THEURET
US-417 [IMP] Imporve code style |
406 |
list = pl_obj.browse(cr, uid, int(arg[2]), context=context) |
374.3.1
by Quentin THEURET
UF-585 [IMP] Filtered products which are in parent list in product list |
407 |
for line in list.product_ids: |
408 |
ids.append(line.name.id) |
|
409 |
elif arg[0] == 'list_ids' and arg[1] == 'in' and arg[2]: |
|
2560.1.1
by Quentin THEURET
US-417 [IMP] Imporve code style |
410 |
for list in pl_obj.browse(cr, uid, arg[2], context=context): |
374.3.1
by Quentin THEURET
UF-585 [IMP] Filtered products which are in parent list in product list |
411 |
for line in list.product_ids: |
412 |
ids.append(line.name.id) |
|
413 |
else: |
|
414 |
return [] |
|
2560.1.1
by Quentin THEURET
US-417 [IMP] Imporve code style |
415 |
|
374.3.1
by Quentin THEURET
UF-585 [IMP] Filtered products which are in parent list in product list |
416 |
return [('id', 'in', ids)] |
417 |
||
418 |
_columns = { |
|
2560.1.1
by Quentin THEURET
US-417 [IMP] Imporve code style |
419 |
'list_ids': fields.function( |
420 |
_get_list_sublist, |
|
421 |
fnct_search=_search_list_sublist, |
|
422 |
type='many2many', |
|
423 |
relation='product.list', |
|
424 |
method=True, |
|
425 |
string='Lists', |
|
426 |
),
|
|
1249.10.34
by matthieu.choplin at msf
[uf-1544] come back to revno 1268 with the default_code and the international_status required in the view but not in the python code (to pass the data and the yml tests) |
427 |
# we can't write the default_code required because it is used in the product addons
|
2298.12.2
by vg at tempo-consulting
UFTP-327 [IMP] product default_code pass from 14 to 18 chars |
428 |
# UFTP-327 default_code passed from size 14 to 18
|
429 |
# http://jira.unifield.org/browse/UFTP-327?focusedCommentId=36173&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-36173
|
|
2560.1.1
by Quentin THEURET
US-417 [IMP] Imporve code style |
430 |
'default_code': fields.char( |
431 |
string='CODE', |
|
432 |
size=18, |
|
433 |
select=True, |
|
434 |
),
|
|
435 |
'msfid': fields.integer( |
|
436 |
string='Hidden field for UniData', |
|
437 |
), # US-45: Added this field but hidden, for UniData to be able to import the Id |
|
438 |
'xmlid_code': fields.char( |
|
439 |
'Hidden xmlid code', |
|
440 |
size=18, |
|
441 |
), # UF-2254: this code is only used for xml_id purpose, added ONLY when creating the product |
|
374.3.1
by Quentin THEURET
UF-585 [IMP] Filtered products which are in parent list in product list |
442 |
}
|
443 |
||
1249.10.34
by matthieu.choplin at msf
[uf-1544] come back to revno 1268 with the default_code and the international_status required in the view but not in the python code (to pass the data and the yml tests) |
444 |
_sql_constraints = [ |
2560.1.1
by Quentin THEURET
US-417 [IMP] Imporve code style |
445 |
(
|
446 |
'default_code', |
|
447 |
"unique(default_code)", |
|
448 |
'The "Product Code" must be unique', |
|
449 |
),
|
|
450 |
(
|
|
451 |
'xmlid_code', |
|
452 |
"unique(xmlid_code)", |
|
453 |
'The xmlid_code must be unique', |
|
454 |
),
|
|
1249.10.34
by matthieu.choplin at msf
[uf-1544] come back to revno 1268 with the default_code and the international_status required in the view but not in the python code (to pass the data and the yml tests) |
455 |
]
|
2560.1.1
by Quentin THEURET
US-417 [IMP] Imporve code style |
456 |
|
2698.2.21
by Fabien MORIN
SP-223 [FIX] After discussion with JFB, the way to introduce force_no_order |
457 |
def search(self, cr, uid, args, offset=0, limit=None, order=None, context=None, count=False): |
2569.2.1
by Quentin THEURET
US-453 [FIX] When use the Object query and make a query on sublist field of products, the result doesn't show products of the list |
458 |
"""
|
459 |
Customize the search() method to include the search of products in a specific list
|
|
460 |
"""
|
|
461 |
pl_obj = self.pool.get('product.list') |
|
462 |
pll_obj = self.pool.get('product.list.line') |
|
463 |
||
464 |
iargs = -1 |
|
465 |
for a in args: |
|
466 |
iargs += 1 |
|
467 |
if a[0] == 'sublist': |
|
468 |
prd_domain = set() |
|
469 |
pl_ids = pl_obj.search(cr, uid, [ |
|
470 |
('name', a[1], a[2]) |
|
2698.2.26
by Fabien MORIN
SP-223 [IMP] set a variable equals to args.append instead of calling many times |
471 |
], order='NO_ORDER', context=context) |
2569.2.1
by Quentin THEURET
US-453 [FIX] When use the Object query and make a query on sublist field of products, the result doesn't show products of the list |
472 |
pll_ids = pll_obj.search(cr, uid, [ |
473 |
('list_id', 'in', pl_ids), |
|
2698.2.26
by Fabien MORIN
SP-223 [IMP] set a variable equals to args.append instead of calling many times |
474 |
], order='NO_ORDER', context=context) |
2569.2.1
by Quentin THEURET
US-453 [FIX] When use the Object query and make a query on sublist field of products, the result doesn't show products of the list |
475 |
for line in pll_obj.browse(cr, uid, pll_ids, context=context): |
476 |
prd_domain.add(line.name.id) |
|
477 |
||
478 |
del args[iargs] |
|
479 |
args.append(('id', 'in', list(prd_domain))) |
|
480 |
||
481 |
# In case of no list found or no line in lists, empty list
|
|
482 |
if not prd_domain: |
|
483 |
return [] |
|
484 |
||
2698.2.20
by Fabien MORIN
SP-223 [ADD] force_no_order parameter |
485 |
return super(product_product, self).search(cr, uid, args, offset, |
2698.2.21
by Fabien MORIN
SP-223 [FIX] After discussion with JFB, the way to introduce force_no_order |
486 |
limit, order, context, count) |
2569.2.1
by Quentin THEURET
US-453 [FIX] When use the Object query and make a query on sublist field of products, the result doesn't show products of the list |
487 |
|
1939.2.1
by jf
UF-2254 [FIX] unique xmlid_code: prevent infinite loop |
488 |
def write(self, cr, uid, ids, value, context=None): |
489 |
single = False |
|
490 |
if isinstance(ids, (long, int)): |
|
491 |
ids = [ids] |
|
492 |
single = True |
|
493 |
if value.get('default_code') and value['default_code'] != 'XXX': |
|
494 |
# do we have any ids with default_code set to 'XXX'
|
|
2560.1.1
by Quentin THEURET
US-417 [IMP] Imporve code style |
495 |
xxx_ids = self.search(cr, uid, [ |
496 |
('id', 'in', ids), |
|
497 |
('default_code', '=', 'XXX'), |
|
2698.2.27
by Fabien MORIN
SP-223 [IMP] add limit=1, count=True in the places we just one to know if a |
498 |
], order='NO_ORDER', context=context) |
1939.2.1
by jf
UF-2254 [FIX] unique xmlid_code: prevent infinite loop |
499 |
if xxx_ids: |
2560.1.1
by Quentin THEURET
US-417 [IMP] Imporve code style |
500 |
self.write(cr, uid, xxx_ids, { |
501 |
'xmlid_code': value['default_code'], |
|
502 |
}, context=context) |
|
503 |
return super(product_product, self).\ |
|
504 |
write(cr, uid, single and ids[0] or ids, value, context=context) |
|
1908.2.2
by dvo at dvo
UF-2254: Allow to modify the product code - new column added |
505 |
|
374.3.1
by Quentin THEURET
UF-585 [IMP] Filtered products which are in parent list in product list |
506 |
product_product() |
507 |
||
2560.1.1
by Quentin THEURET
US-417 [IMP] Imporve code style |
508 |
|
896.6.2
by matthieu.choplin at msf
[FIX] bug on the renaming of 'Name' and 'Code' of the product and customize view |
509 |
class product_template(osv.osv): |
510 |
_name = 'product.template' |
|
511 |
_inherit = 'product.template' |
|
512 |
||
2560.1.1
by Quentin THEURET
US-417 [IMP] Imporve code style |
513 |
# SP-193 : Change field size 60 to 128 digits
|
896.6.2
by matthieu.choplin at msf
[FIX] bug on the renaming of 'Name' and 'Code' of the product and customize view |
514 |
_columns = { |
2560.1.1
by Quentin THEURET
US-417 [IMP] Imporve code style |
515 |
'name': fields.char( |
516 |
size=128, |
|
517 |
string='DESCRIPTION', |
|
518 |
required=True, |
|
519 |
translate=True, |
|
520 |
),
|
|
896.6.2
by matthieu.choplin at msf
[FIX] bug on the renaming of 'Name' and 'Code' of the product and customize view |
521 |
}
|
522 |
product_template() |
|
523 |
||
374.3.1
by Quentin THEURET
UF-585 [IMP] Filtered products which are in parent list in product list |
524 |
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|