210
by Alex Comba
[ADD] product_pack module 6.1 version |
1 |
# -*- coding: utf-8 -*-
|
213
by Alex Comba
[IMP] Add PEP8 style check using flake8 |
2 |
###############################################################################
|
210
by Alex Comba
[ADD] product_pack module 6.1 version |
3 |
#
|
4 |
# Copyright (c) 2009 Angel Alvarez - NaN (http://www.nan-tic.com)
|
|
5 |
# Copyright (C) 2012 Domsense srl (<http://www.domsense.com>)
|
|
213
by Alex Comba
[IMP] Add PEP8 style check using flake8 |
6 |
# Copyright (C) 2013 Agile Business Group sagl (<http://www.agilebg.com>)
|
210
by Alex Comba
[ADD] product_pack module 6.1 version |
7 |
#
|
8 |
# This program is free software: you can redistribute it and/or modify
|
|
9 |
# it under the terms of the GNU Affero General Public License as published
|
|
10 |
# by the Free Software Foundation, either version 3 of the License, or
|
|
11 |
# (at your option) any later version.
|
|
12 |
#
|
|
13 |
# This program is distributed in the hope that it will be useful,
|
|
14 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
211
by Alex Comba
[REF] product_stock module porting to 7.0 |
16 |
# GNU Affero General Public License for more details.
|
210
by Alex Comba
[ADD] product_pack module 6.1 version |
17 |
#
|
18 |
# You should have received a copy of the GNU Affero General Public License
|
|
19 |
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
20 |
#
|
|
213
by Alex Comba
[IMP] Add PEP8 style check using flake8 |
21 |
###############################################################################
|
210
by Alex Comba
[ADD] product_pack module 6.1 version |
22 |
|
23 |
import math |
|
211
by Alex Comba
[REF] product_stock module porting to 7.0 |
24 |
from openerp.osv import fields, orm |
25 |
||
26 |
||
27 |
class product_pack(orm.Model): |
|
210
by Alex Comba
[ADD] product_pack module 6.1 version |
28 |
_name = 'product.pack.line' |
29 |
_rec_name = 'product_id' |
|
30 |
_columns = { |
|
213
by Alex Comba
[IMP] Add PEP8 style check using flake8 |
31 |
'parent_product_id': fields.many2one( |
32 |
'product.product', 'Parent Product', |
|
33 |
ondelete='cascade', required=True |
|
34 |
),
|
|
212
by Alex Comba
[REM] empty spaces close to arguments |
35 |
'quantity': fields.float('Quantity', required=True), |
213
by Alex Comba
[IMP] Add PEP8 style check using flake8 |
36 |
'product_id': fields.many2one( |
37 |
'product.product', 'Product', required=True |
|
38 |
),
|
|
210
by Alex Comba
[ADD] product_pack module 6.1 version |
39 |
}
|
40 |
||
213
by Alex Comba
[IMP] Add PEP8 style check using flake8 |
41 |
|
211
by Alex Comba
[REF] product_stock module porting to 7.0 |
42 |
class product_product(orm.Model): |
210
by Alex Comba
[ADD] product_pack module 6.1 version |
43 |
_inherit = 'product.product' |
44 |
_columns = { |
|
213
by Alex Comba
[IMP] Add PEP8 style check using flake8 |
45 |
'stock_depends': fields.boolean( |
46 |
'Stock depends of components', |
|
47 |
help='Mark if pack stock is calcualted from component stock' |
|
48 |
),
|
|
49 |
'pack_fixed_price': fields.boolean( |
|
50 |
'Pack has fixed price', |
|
51 |
help=""" |
|
52 |
Mark this field if the public price of the pack should be fixed.
|
|
53 |
Do not mark it if the price should be calculated from the sum of
|
|
54 |
the prices of the products in the pack.
|
|
55 |
"""
|
|
56 |
),
|
|
57 |
'pack_line_ids': fields.one2many( |
|
58 |
'product.pack.line', 'parent_product_id', 'Pack Products', |
|
59 |
help='List of products that are part of this pack.' |
|
60 |
),
|
|
210
by Alex Comba
[ADD] product_pack module 6.1 version |
61 |
}
|
62 |
||
211
by Alex Comba
[REF] product_stock module porting to 7.0 |
63 |
def get_product_available(self, cr, uid, ids, context=None): |
213
by Alex Comba
[IMP] Add PEP8 style check using flake8 |
64 |
"""
|
65 |
Calulate stock for packs
|
|
66 |
:return: maximum stock that lets complete pack
|
|
67 |
"""
|
|
68 |
result = {} |
|
212
by Alex Comba
[REM] empty spaces close to arguments |
69 |
for product in self.browse(cr, uid, ids, context=context): |
213
by Alex Comba
[IMP] Add PEP8 style check using flake8 |
70 |
stock = super(product_product, self).get_product_available( |
71 |
cr, uid, [product.id], context=context) |
|
210
by Alex Comba
[ADD] product_pack module 6.1 version |
72 |
|
73 |
# Check if product stock depends on it's subproducts stock.
|
|
74 |
if not product.stock_depends: |
|
211
by Alex Comba
[REF] product_stock module porting to 7.0 |
75 |
result[product.id] = stock[product.id] |
210
by Alex Comba
[ADD] product_pack module 6.1 version |
76 |
continue
|
77 |
||
78 |
first_subproduct = True |
|
79 |
pack_stock = 0 |
|
80 |
||
81 |
# Check if the pack has subproducts
|
|
82 |
if product.pack_line_ids: |
|
83 |
||
84 |
# Take the stock/virtual stock of all subproducts
|
|
213
by Alex Comba
[IMP] Add PEP8 style check using flake8 |
85 |
subproducts_stock = self.get_product_available( |
86 |
cr, |
|
87 |
uid, |
|
88 |
[line.product_id.id for line in product.pack_line_ids], |
|
89 |
context=context |
|
90 |
)
|
|
210
by Alex Comba
[ADD] product_pack module 6.1 version |
91 |
|
213
by Alex Comba
[IMP] Add PEP8 style check using flake8 |
92 |
""" Go over all subproducts, take quantity needed for the pack
|
93 |
and its available stock """
|
|
210
by Alex Comba
[ADD] product_pack module 6.1 version |
94 |
for subproduct in product.pack_line_ids: |
95 |
||
96 |
# if subproduct is a service don't calculate the stock
|
|
97 |
if subproduct.product_id.type == 'service': |
|
98 |
continue
|
|
99 |
if first_subproduct: |
|
100 |
subproduct_quantity = subproduct.quantity |
|
213
by Alex Comba
[IMP] Add PEP8 style check using flake8 |
101 |
subproduct_stock = ( |
102 |
subproducts_stock[subproduct.product_id.id]) |
|
210
by Alex Comba
[ADD] product_pack module 6.1 version |
103 |
if subproduct_quantity == 0: |
104 |
continue
|
|
105 |
||
213
by Alex Comba
[IMP] Add PEP8 style check using flake8 |
106 |
""" Calculate real stock for current pack from the
|
107 |
subproduct stock and needed quantity """
|
|
108 |
pack_stock = math.floor( |
|
109 |
subproduct_stock / subproduct_quantity) |
|
210
by Alex Comba
[ADD] product_pack module 6.1 version |
110 |
first_subproduct = False |
111 |
continue
|
|
112 |
||
113 |
# Take the info of the next subproduct
|
|
114 |
subproduct_quantity_next = subproduct.quantity |
|
213
by Alex Comba
[IMP] Add PEP8 style check using flake8 |
115 |
subproduct_stock_next = ( |
116 |
subproducts_stock[subproduct.product_id.id]) |
|
117 |
||
118 |
if ( |
|
119 |
subproduct_quantity_next == 0 |
|
120 |
or subproduct_quantity_next == 0.0 |
|
121 |
):
|
|
210
by Alex Comba
[ADD] product_pack module 6.1 version |
122 |
continue
|
213
by Alex Comba
[IMP] Add PEP8 style check using flake8 |
123 |
|
124 |
pack_stock_next = math.floor( |
|
125 |
subproduct_stock_next / subproduct_quantity_next) |
|
210
by Alex Comba
[ADD] product_pack module 6.1 version |
126 |
|
127 |
# compare the stock of a subproduct and the next subproduct
|
|
128 |
if pack_stock_next < pack_stock: |
|
129 |
pack_stock = pack_stock_next |
|
130 |
||
131 |
# result is the minimum stock of all subproducts
|
|
211
by Alex Comba
[REF] product_stock module porting to 7.0 |
132 |
result[product.id] = pack_stock |
210
by Alex Comba
[ADD] product_pack module 6.1 version |
133 |
else: |
211
by Alex Comba
[REF] product_stock module porting to 7.0 |
134 |
result[product.id] = stock[product.id] |
210
by Alex Comba
[ADD] product_pack module 6.1 version |
135 |
return result |
136 |
||
211
by Alex Comba
[REF] product_stock module porting to 7.0 |
137 |
|
138 |
class sale_order_line(orm.Model): |
|
210
by Alex Comba
[ADD] product_pack module 6.1 version |
139 |
_inherit = 'sale.order.line' |
140 |
_columns = { |
|
213
by Alex Comba
[IMP] Add PEP8 style check using flake8 |
141 |
'pack_depth': fields.integer( |
142 |
'Depth', required=True, |
|
143 |
help='Depth of the product if it is part of a pack.' |
|
144 |
),
|
|
145 |
'pack_parent_line_id': fields.many2one( |
|
146 |
'sale.order.line', 'Pack', |
|
147 |
help='The pack that contains this product.' |
|
148 |
),
|
|
149 |
'pack_child_line_ids': fields.one2many( |
|
150 |
'sale.order.line', 'pack_parent_line_id', 'Lines in pack'), |
|
210
by Alex Comba
[ADD] product_pack module 6.1 version |
151 |
}
|
152 |
_defaults = { |
|
153 |
'pack_depth': lambda *a: 0, |
|
154 |
}
|
|
155 |
||
211
by Alex Comba
[REF] product_stock module porting to 7.0 |
156 |
|
157 |
class sale_order(orm.Model): |
|
210
by Alex Comba
[ADD] product_pack module 6.1 version |
158 |
_inherit = 'sale.order' |
159 |
||
160 |
def create(self, cr, uid, vals, context=None): |
|
213
by Alex Comba
[IMP] Add PEP8 style check using flake8 |
161 |
result = super(sale_order, self).create(cr, uid, vals, context) |
210
by Alex Comba
[ADD] product_pack module 6.1 version |
162 |
self.expand_packs(cr, uid, [result], context) |
163 |
return result |
|
164 |
||
165 |
def write(self, cr, uid, ids, vals, context=None): |
|
213
by Alex Comba
[IMP] Add PEP8 style check using flake8 |
166 |
result = super(sale_order, self).write(cr, uid, ids, vals, context) |
210
by Alex Comba
[ADD] product_pack module 6.1 version |
167 |
self.expand_packs(cr, uid, ids, context) |
168 |
return result |
|
169 |
||
170 |
def expand_packs(self, cr, uid, ids, context={}, depth=1): |
|
171 |
if type(ids) in [int, long]: |
|
172 |
ids = [ids] |
|
173 |
if depth == 10: |
|
174 |
return
|
|
175 |
updated_orders = [] |
|
176 |
for order in self.browse(cr, uid, ids, context): |
|
177 |
||
213
by Alex Comba
[IMP] Add PEP8 style check using flake8 |
178 |
fiscal_position = ( |
179 |
order.fiscal_position |
|
180 |
and self.pool.get('account.fiscal.position').browse( |
|
181 |
cr, uid, order.fiscal_position.id, context |
|
182 |
)
|
|
183 |
or False |
|
184 |
)
|
|
185 |
"""
|
|
186 |
The reorder variable is used to ensure lines of the same pack go
|
|
187 |
right after their parent. What the algorithm does is check if the
|
|
188 |
previous item had children. As children items must go right after
|
|
189 |
the parent if the line we're evaluating doesn't have a parent it
|
|
190 |
means it's a new item (and probably has the default 10 sequence
|
|
191 |
number - unless the appropiate c2c_sale_sequence module is
|
|
192 |
installed). In this case we mark the item for reordering and
|
|
193 |
evaluate the next one. Note that as the item is not evaluated and
|
|
194 |
it might have to be expanded it's put on the queue for another
|
|
195 |
iteration (it's simple and works well). Once the next item has been
|
|
196 |
evaluated the sequence of the item marked for reordering is updated
|
|
197 |
with the next value.
|
|
198 |
"""
|
|
210
by Alex Comba
[ADD] product_pack module 6.1 version |
199 |
sequence = -1 |
200 |
reorder = [] |
|
201 |
last_had_children = False |
|
202 |
for line in order.order_line: |
|
203 |
if last_had_children and not line.pack_parent_line_id: |
|
212
by Alex Comba
[REM] empty spaces close to arguments |
204 |
reorder.append(line.id) |
213
by Alex Comba
[IMP] Add PEP8 style check using flake8 |
205 |
if ( |
206 |
line.product_id.pack_line_ids |
|
207 |
and not order.id in updated_orders |
|
208 |
):
|
|
212
by Alex Comba
[REM] empty spaces close to arguments |
209 |
updated_orders.append(order.id) |
210
by Alex Comba
[ADD] product_pack module 6.1 version |
210 |
continue
|
211 |
||
212 |
sequence += 1 |
|
213 |
||
214 |
if sequence > line.sequence: |
|
213
by Alex Comba
[IMP] Add PEP8 style check using flake8 |
215 |
self.pool.get('sale.order.line').write( |
216 |
cr, uid, [line.id], {'sequence': sequence, }, context) |
|
210
by Alex Comba
[ADD] product_pack module 6.1 version |
217 |
else: |
218 |
sequence = line.sequence |
|
219 |
||
220 |
if line.state != 'draft': |
|
221 |
continue
|
|
222 |
if not line.product_id: |
|
223 |
continue
|
|
224 |
||
213
by Alex Comba
[IMP] Add PEP8 style check using flake8 |
225 |
""" If pack was already expanded (in another create/write
|
226 |
operation or in a previous iteration) don't do it again. """
|
|
210
by Alex Comba
[ADD] product_pack module 6.1 version |
227 |
if line.pack_child_line_ids: |
228 |
last_had_children = True |
|
229 |
continue
|
|
230 |
last_had_children = False |
|
231 |
||
232 |
for subline in line.product_id.pack_line_ids: |
|
233 |
sequence += 1 |
|
234 |
||
235 |
subproduct = subline.product_id |
|
236 |
quantity = subline.quantity * line.product_uom_qty |
|
237 |
||
238 |
if line.product_id.pack_fixed_price: |
|
239 |
price = 0.0 |
|
240 |
discount = 0.0 |
|
241 |
else: |
|
242 |
pricelist = order.pricelist_id.id |
|
213
by Alex Comba
[IMP] Add PEP8 style check using flake8 |
243 |
price = self.pool.get('product.pricelist').price_get( |
244 |
cr, uid, [pricelist], subproduct.id, quantity, |
|
245 |
order.partner_id.id, { |
|
246 |
'uom': subproduct.uom_id.id, |
|
247 |
'date': order.date_order, |
|
248 |
}
|
|
249 |
)[pricelist] |
|
210
by Alex Comba
[ADD] product_pack module 6.1 version |
250 |
discount = line.discount |
251 |
||
252 |
# Obtain product name in partner's language
|
|
253 |
ctx = {'lang': order.partner_id.lang} |
|
213
by Alex Comba
[IMP] Add PEP8 style check using flake8 |
254 |
subproduct_name = self.pool.get('product.product').browse( |
255 |
cr, uid, subproduct.id, ctx).name |
|
210
by Alex Comba
[ADD] product_pack module 6.1 version |
256 |
|
213
by Alex Comba
[IMP] Add PEP8 style check using flake8 |
257 |
tax_ids = self.pool.get('account.fiscal.position').map_tax( |
258 |
cr, uid, fiscal_position, subproduct.taxes_id) |
|
210
by Alex Comba
[ADD] product_pack module 6.1 version |
259 |
|
260 |
if subproduct.uos_id: |
|
261 |
uos_id = subproduct.uos_id.id |
|
262 |
uos_qty = quantity * subproduct.uos_coeff |
|
263 |
else: |
|
264 |
uos_id = False |
|
265 |
uos_qty = quantity |
|
266 |
||
267 |
vals = { |
|
268 |
'order_id': order.id, |
|
213
by Alex Comba
[IMP] Add PEP8 style check using flake8 |
269 |
'name': '%s%s' % ( |
270 |
'> ' * (line.pack_depth+1), subproduct_name |
|
271 |
),
|
|
210
by Alex Comba
[ADD] product_pack module 6.1 version |
272 |
'sequence': sequence, |
273 |
'delay': subproduct.sale_delay or 0.0, |
|
274 |
'product_id': subproduct.id, |
|
213
by Alex Comba
[IMP] Add PEP8 style check using flake8 |
275 |
'procurement_id': ( |
276 |
line.procurement_id |
|
277 |
and line.procurement_id.id |
|
278 |
or False |
|
279 |
),
|
|
210
by Alex Comba
[ADD] product_pack module 6.1 version |
280 |
'price_unit': price, |
213
by Alex Comba
[IMP] Add PEP8 style check using flake8 |
281 |
'tax_id': [(6, 0, tax_ids)], |
210
by Alex Comba
[ADD] product_pack module 6.1 version |
282 |
'type': subproduct.procure_method, |
213
by Alex Comba
[IMP] Add PEP8 style check using flake8 |
283 |
'property_ids': [(6, 0, [])], |
210
by Alex Comba
[ADD] product_pack module 6.1 version |
284 |
'address_allotment_id': False, |
285 |
'product_uom_qty': quantity, |
|
286 |
'product_uom': subproduct.uom_id.id, |
|
287 |
'product_uos_qty': uos_qty, |
|
288 |
'product_uos': uos_id, |
|
289 |
'product_packaging': False, |
|
213
by Alex Comba
[IMP] Add PEP8 style check using flake8 |
290 |
'move_ids': [(6, 0, [])], |
210
by Alex Comba
[ADD] product_pack module 6.1 version |
291 |
'discount': discount, |
292 |
'number_packages': False, |
|
293 |
'notes': False, |
|
294 |
'th_weight': False, |
|
295 |
'state': 'draft', |
|
296 |
'pack_parent_line_id': line.id, |
|
297 |
'pack_depth': line.pack_depth + 1, |
|
298 |
}
|
|
299 |
||
213
by Alex Comba
[IMP] Add PEP8 style check using flake8 |
300 |
""" It's a control for the case that the
|
301 |
nan_external_prices was installed with the product pack """
|
|
210
by Alex Comba
[ADD] product_pack module 6.1 version |
302 |
if 'prices_used' in line: |
212
by Alex Comba
[REM] empty spaces close to arguments |
303 |
vals['prices_used'] = line.prices_used |
210
by Alex Comba
[ADD] product_pack module 6.1 version |
304 |
|
213
by Alex Comba
[IMP] Add PEP8 style check using flake8 |
305 |
self.pool.get('sale.order.line').create( |
306 |
cr, uid, vals, context) |
|
210
by Alex Comba
[ADD] product_pack module 6.1 version |
307 |
if not order.id in updated_orders: |
212
by Alex Comba
[REM] empty spaces close to arguments |
308 |
updated_orders.append(order.id) |
210
by Alex Comba
[ADD] product_pack module 6.1 version |
309 |
|
310 |
for id in reorder: |
|
311 |
sequence += 1 |
|
213
by Alex Comba
[IMP] Add PEP8 style check using flake8 |
312 |
self.pool.get('sale.order.line').write( |
313 |
cr, uid, [id], {'sequence': sequence, }, context) |
|
210
by Alex Comba
[ADD] product_pack module 6.1 version |
314 |
|
315 |
if updated_orders: |
|
213
by Alex Comba
[IMP] Add PEP8 style check using flake8 |
316 |
""" Try to expand again all those orders that had a pack in this
|
317 |
iteration. This way we support packs inside other packs. """
|
|
212
by Alex Comba
[REM] empty spaces close to arguments |
318 |
self.expand_packs(cr, uid, ids, context, depth + 1) |
210
by Alex Comba
[ADD] product_pack module 6.1 version |
319 |
return
|
320 |
||
211
by Alex Comba
[REF] product_stock module porting to 7.0 |
321 |
|
322 |
class purchase_order_line(orm.Model): |
|
210
by Alex Comba
[ADD] product_pack module 6.1 version |
323 |
_inherit = 'purchase.order.line' |
324 |
_columns = { |
|
213
by Alex Comba
[IMP] Add PEP8 style check using flake8 |
325 |
'sequence': fields.integer( |
326 |
'Sequence', |
|
327 |
help="""Gives the sequence order when displaying a list of |
|
328 |
purchase order lines. """
|
|
329 |
),
|
|
330 |
'pack_depth': fields.integer( |
|
331 |
'Depth', required=True, |
|
332 |
help='Depth of the product if it is part of a pack.' |
|
333 |
),
|
|
334 |
'pack_parent_line_id': fields.many2one( |
|
335 |
'purchase.order.line', 'Pack', |
|
336 |
help='The pack that contains this product.' |
|
337 |
),
|
|
338 |
'pack_child_line_ids': fields.one2many( |
|
339 |
'purchase.order.line', 'pack_parent_line_id', 'Lines in pack' |
|
340 |
),
|
|
210
by Alex Comba
[ADD] product_pack module 6.1 version |
341 |
}
|
342 |
_defaults = { |
|
343 |
'pack_depth': lambda *a: 0, |
|
344 |
}
|
|
345 |
||
211
by Alex Comba
[REF] product_stock module porting to 7.0 |
346 |
|
347 |
class purchase_order(orm.Model): |
|
210
by Alex Comba
[ADD] product_pack module 6.1 version |
348 |
_inherit = 'purchase.order' |
349 |
||
350 |
def create(self, cr, uid, vals, context=None): |
|
213
by Alex Comba
[IMP] Add PEP8 style check using flake8 |
351 |
result = super(purchase_order, self).create(cr, uid, vals, context) |
210
by Alex Comba
[ADD] product_pack module 6.1 version |
352 |
self.expand_packs(cr, uid, [result], context) |
353 |
return result |
|
354 |
||
355 |
def write(self, cr, uid, ids, vals, context=None): |
|
213
by Alex Comba
[IMP] Add PEP8 style check using flake8 |
356 |
result = super(purchase_order, self).write(cr, uid, ids, vals, context) |
210
by Alex Comba
[ADD] product_pack module 6.1 version |
357 |
self.expand_packs(cr, uid, ids, context) |
358 |
return result |
|
359 |
||
360 |
def expand_packs(self, cr, uid, ids, context={}, depth=1): |
|
361 |
if type(ids) in [int, long]: |
|
362 |
ids = [ids] |
|
363 |
if depth == 10: |
|
364 |
return
|
|
365 |
updated_orders = [] |
|
366 |
for order in self.browse(cr, uid, ids, context): |
|
213
by Alex Comba
[IMP] Add PEP8 style check using flake8 |
367 |
fiscal_position = ( |
368 |
order.fiscal_position |
|
369 |
and self.pool.get('account.fiscal.position').browse( |
|
370 |
cr, uid, order.fiscal_position.id, context |
|
371 |
)
|
|
372 |
or False |
|
373 |
)
|
|
374 |
"""
|
|
375 |
The reorder variable is used to ensure lines of the same pack go
|
|
376 |
right after their parent. What the algorithm does is check if the
|
|
377 |
previous item had children. As children items must go right after
|
|
378 |
the parent if the line we're evaluating doesn't have a parent it
|
|
379 |
means it's a new item (and probably has the default 10 sequence
|
|
380 |
number - unless the appropiate c2c_sale_sequence module is
|
|
381 |
installed). In this case we mark the item for reordering and
|
|
382 |
evaluate the next one. Note that as the item is not evaluated and
|
|
383 |
it might have to be expanded it's put on the queue for another
|
|
384 |
iteration (it's simple and works well). Once the next item has been
|
|
385 |
evaluated the sequence of the item marked for reordering is updated
|
|
386 |
with the next value.
|
|
387 |
"""
|
|
210
by Alex Comba
[ADD] product_pack module 6.1 version |
388 |
sequence = -1 |
389 |
reorder = [] |
|
390 |
last_had_children = False |
|
391 |
for line in order.order_line: |
|
392 |
if last_had_children and not line.pack_parent_line_id: |
|
212
by Alex Comba
[REM] empty spaces close to arguments |
393 |
reorder.append(line.id) |
213
by Alex Comba
[IMP] Add PEP8 style check using flake8 |
394 |
if ( |
395 |
line.product_id.pack_line_ids |
|
396 |
and not order.id in updated_orders |
|
397 |
):
|
|
212
by Alex Comba
[REM] empty spaces close to arguments |
398 |
updated_orders.append(order.id) |
210
by Alex Comba
[ADD] product_pack module 6.1 version |
399 |
continue
|
400 |
||
401 |
sequence += 1 |
|
402 |
||
403 |
if sequence > line.sequence: |
|
213
by Alex Comba
[IMP] Add PEP8 style check using flake8 |
404 |
self.pool.get('purchase.order.line').write( |
405 |
cr, uid, [line.id], {'sequence': sequence, }, context) |
|
210
by Alex Comba
[ADD] product_pack module 6.1 version |
406 |
else: |
407 |
sequence = line.sequence |
|
408 |
||
409 |
if line.state != 'draft': |
|
410 |
continue
|
|
411 |
if not line.product_id: |
|
412 |
continue
|
|
413 |
||
213
by Alex Comba
[IMP] Add PEP8 style check using flake8 |
414 |
# If pack was already expanded (in another create/write
|
415 |
# operation or in a previous iteration) don't do it again.
|
|
210
by Alex Comba
[ADD] product_pack module 6.1 version |
416 |
if line.pack_child_line_ids: |
417 |
last_had_children = True |
|
418 |
continue
|
|
419 |
last_had_children = False |
|
420 |
||
421 |
for subline in line.product_id.pack_line_ids: |
|
422 |
sequence += 1 |
|
423 |
||
424 |
subproduct = subline.product_id |
|
425 |
quantity = subline.quantity * line.product_qty |
|
426 |
||
427 |
if line.product_id.pack_fixed_price: |
|
428 |
price = 0.0 |
|
429 |
else: |
|
430 |
pricelist = order.pricelist_id.id |
|
213
by Alex Comba
[IMP] Add PEP8 style check using flake8 |
431 |
price = self.pool.get('product.pricelist').price_get( |
432 |
cr, uid, [pricelist], subproduct.id, quantity, |
|
433 |
order.partner_id.id, { |
|
434 |
'uom': subproduct.uom_id.id, |
|
435 |
'date': order.date_order, |
|
436 |
}
|
|
437 |
)[pricelist] |
|
210
by Alex Comba
[ADD] product_pack module 6.1 version |
438 |
|
439 |
# Obtain product name in partner's language
|
|
440 |
ctx = {'lang': order.partner_id.lang} |
|
213
by Alex Comba
[IMP] Add PEP8 style check using flake8 |
441 |
subproduct_name = self.pool.get('product.product').browse( |
442 |
cr, uid, subproduct.id, ctx).name |
|
210
by Alex Comba
[ADD] product_pack module 6.1 version |
443 |
|
213
by Alex Comba
[IMP] Add PEP8 style check using flake8 |
444 |
tax_ids = self.pool.get('account.fiscal.position').map_tax( |
445 |
cr, uid, fiscal_position, subproduct.taxes_id) |
|
210
by Alex Comba
[ADD] product_pack module 6.1 version |
446 |
|
447 |
vals = { |
|
448 |
'order_id': order.id, |
|
213
by Alex Comba
[IMP] Add PEP8 style check using flake8 |
449 |
'name': '%s%s' % ( |
450 |
'> ' * (line.pack_depth + 1), subproduct_name), |
|
210
by Alex Comba
[ADD] product_pack module 6.1 version |
451 |
'date_planned': line.date_planned or 0.0, |
452 |
'sequence': sequence, |
|
453 |
'product_id': subproduct.id, |
|
454 |
'price_unit': price, |
|
213
by Alex Comba
[IMP] Add PEP8 style check using flake8 |
455 |
'taxes_id': [(6, 0, tax_ids)], |
210
by Alex Comba
[ADD] product_pack module 6.1 version |
456 |
'product_qty': quantity, |
457 |
'product_uom': subproduct.uom_id.id, |
|
213
by Alex Comba
[IMP] Add PEP8 style check using flake8 |
458 |
'move_ids': [(6, 0, [])], |
210
by Alex Comba
[ADD] product_pack module 6.1 version |
459 |
'notes': False, |
460 |
'state': 'draft', |
|
461 |
'pack_parent_line_id': line.id, |
|
462 |
'pack_depth': line.pack_depth + 1, |
|
463 |
}
|
|
464 |
||
213
by Alex Comba
[IMP] Add PEP8 style check using flake8 |
465 |
# It's a control for the case that the nan_external_prices
|
466 |
# was installed with the product pack
|
|
210
by Alex Comba
[ADD] product_pack module 6.1 version |
467 |
if 'prices_used' in line: |
212
by Alex Comba
[REM] empty spaces close to arguments |
468 |
vals['prices_used'] = line.prices_used |
210
by Alex Comba
[ADD] product_pack module 6.1 version |
469 |
|
213
by Alex Comba
[IMP] Add PEP8 style check using flake8 |
470 |
self.pool.get('purchase.order.line').create( |
471 |
cr, uid, vals, context) |
|
210
by Alex Comba
[ADD] product_pack module 6.1 version |
472 |
if not order.id in updated_orders: |
212
by Alex Comba
[REM] empty spaces close to arguments |
473 |
updated_orders.append(order.id) |
210
by Alex Comba
[ADD] product_pack module 6.1 version |
474 |
|
475 |
for id in reorder: |
|
476 |
sequence += 1 |
|
213
by Alex Comba
[IMP] Add PEP8 style check using flake8 |
477 |
self.pool.get('purchase.order.line').write( |
478 |
cr, uid, [id], {'sequence': sequence, }, context) |
|
210
by Alex Comba
[ADD] product_pack module 6.1 version |
479 |
|
480 |
if updated_orders: |
|
213
by Alex Comba
[IMP] Add PEP8 style check using flake8 |
481 |
# Try to expand again all those orders that had a pack in
|
482 |
# this iteration. This way we support packs inside other packs.
|
|
212
by Alex Comba
[REM] empty spaces close to arguments |
483 |
self.expand_packs(cr, uid, ids, context, depth + 1) |
213
by Alex Comba
[IMP] Add PEP8 style check using flake8 |
484 |
return
|