Merge lp:~unifield-team/unifield-wm/uftp-404 into lp:unifield-wm
- uftp-404
- Merge into trunk
Proposed by
jftempo
Status: | Merged |
---|---|
Merged at revision: | 2355 |
Proposed branch: | lp:~unifield-team/unifield-wm/uftp-404 |
Merge into: | lp:unifield-wm |
Diff against target: |
304 lines (+144/-124) 1 file modified
msf_supply_doc_export/msf_supply_doc_export.py (+144/-124) |
To merge this branch: | bzr merge lp:~unifield-team/unifield-wm/uftp-404 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
UniField Reviewer Team | Pending | ||
Review via email:
|
Commit message
Description of the change
To post a comment you must log in.
- 2355. By Quentin THEURET @Amaris
-
UFTP-404 [FIX] PO Follow-up: Rewrite the displaying of IN lines
- 2356. By Quentin THEURET @Amaris
-
UFTP-404 [FIX] PO Follow-up: If the product has been changed at reception, display the line number
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'msf_supply_doc_export/msf_supply_doc_export.py' |
2 | --- msf_supply_doc_export/msf_supply_doc_export.py 2014-11-07 14:44:59 +0000 |
3 | +++ msf_supply_doc_export/msf_supply_doc_export.py 2014-11-14 10:46:01 +0000 |
4 | @@ -386,6 +386,27 @@ |
5 | def getPOLineHeaders(self): |
6 | return ['Item','Code','Description','Qty ordered','UoM','Qty received','IN','Qty backorder','Unit Price','IN unit price','Destination','Cost Center'] |
7 | |
8 | + def printAnalyticLines(self, analytic_lines): |
9 | + res = [] |
10 | + # if additional analytic lines print them here. |
11 | + for (index, analytic_line) in list(enumerate(analytic_lines))[1:]: |
12 | + report_line = {} |
13 | + report_line['item'] = '' |
14 | + report_line['code'] = '' |
15 | + report_line['description'] = '' |
16 | + report_line['qty_ordered'] = '' |
17 | + report_line['uom'] = '' |
18 | + report_line['qty_received'] = '' |
19 | + report_line['in'] = '' |
20 | + report_line['qty_backordered'] = '' |
21 | + report_line['unit_price'] = '' |
22 | + report_line['in_unit_price'] = '' |
23 | + report_line['destination'] = analytic_line.get('destination') |
24 | + report_line['cost_centre'] = analytic_line.get('cost_center') |
25 | + res.append(report_line) |
26 | + |
27 | + return res |
28 | + |
29 | def getPOLines(self, po_id): |
30 | ''' developer note: would be a lot easier to write this as a single sql and then use on-break ''' |
31 | # TODO the multiplier is the value populated for no change in stock_move.price_unit |
32 | @@ -393,102 +414,114 @@ |
33 | multiplier = 1.0000100000000001 |
34 | pol_obj = self.pool.get('purchase.order.line') |
35 | prod_obj = self.pool.get('product.product') |
36 | + uom_obj = self.pool.get('product.uom') |
37 | po_line_ids = pol_obj.search(self.cr, self.uid, [('order_id','=',po_id)], order='line_number') |
38 | po_lines = pol_obj.browse(self.cr, self.uid, po_line_ids) |
39 | report_lines = [] |
40 | for line in po_lines: |
41 | - sort_key = float(line.line_number*1000) |
42 | - report_line = {} |
43 | - inline_in = self.getInlineIN(line.id) |
44 | + in_lines = self.getAllLineIN(line.id) |
45 | analytic_lines = self.getAnalyticLines(line) |
46 | - other_ins = [] |
47 | - if inline_in: |
48 | - other_ins = self.getOtherINs(line.id, inline_in.get('id')) |
49 | - report_line['sort_key'] = sort_key |
50 | - report_line['item'] = line.line_number or '' |
51 | - report_line['code'] = line.product_id.default_code or '' |
52 | - report_line['description'] = line.product_id.name or '' |
53 | - report_line['qty_ordered'] = line.product_qty or '' |
54 | - report_line['uom'] = line.product_uom.name or '' |
55 | - report_line['qty_received'] = inline_in.get('state') == 'done' and inline_in.get('product_qty','') or '0.00' |
56 | - report_line['in'] = inline_in.get('name','') or '' |
57 | - if inline_in.get('backorder_id') and inline_in.get('state') != 'done': |
58 | - report_line['qty_backordered'] = inline_in.get('product_qty', '') |
59 | - else: |
60 | - report_line['qty_backordered'] = '' |
61 | - report_line['unit_price'] = line.price_unit or '' |
62 | - if inline_in.get('price_unit') and inline_in.get('price_unit') <> multiplier: |
63 | - report_line['in_unit_price'] = inline_in.get('price_unit') |
64 | - else: |
65 | - report_line['in_unit_price'] = '' |
66 | -# report_line['in_unit_price'] = '' |
67 | - report_line['destination'] = analytic_lines[0].get('destination') |
68 | - report_line['cost_centre'] = analytic_lines[0].get('cost_center') |
69 | - report_lines.append(report_line) |
70 | - if inline_in.get('state') != 'done': |
71 | - report_line['in_unit_price'] = '' |
72 | - |
73 | - # if additional analytic lines print them here. |
74 | - for (index, analytic_line) in list(enumerate(analytic_lines))[1:]: |
75 | - report_line = {} |
76 | - sort_key += 1 |
77 | - report_line['sort_key'] = sort_key |
78 | - report_line['item'] = '' |
79 | - report_line['code'] = '' |
80 | - report_line['description'] = '' |
81 | - report_line['qty_ordered'] = '' |
82 | - report_line['uom'] = '' |
83 | - report_line['qty_received'] = '' |
84 | - report_line['in'] = '' |
85 | - report_line['qty_backordered'] = '' |
86 | - report_line['unit_price'] = '' |
87 | - report_line['in_unit_price'] = '' |
88 | - report_line['destination'] = analytic_line.get('destination') |
89 | - report_line['cost_centre'] = analytic_line.get('cost_center') |
90 | - report_lines.append(report_line) |
91 | - |
92 | - # check if there are additional INs for this line |
93 | - if other_ins: |
94 | - for other_in in other_ins: |
95 | - report_line = {} |
96 | - backorder = inline_in.get('backorder_id') and other_in.get('picking_id') == inline_in.get('backorder_id') |
97 | - sort_key += 1 |
98 | - report_line['sort_key'] = sort_key |
99 | - |
100 | - # Product is changed |
101 | - if other_in.get('product_id') and other_in.get('product_id') != line.product_id.id: |
102 | - prod_brw = prod_obj.browse(self.cr, self.uid, other_in.get('product_id')) |
103 | - report_line['code'] = prod_brw.default_code |
104 | - report_line['description'] = prod_brw.name |
105 | - else: |
106 | - report_line['code'] = '' |
107 | - report_line['description'] = '' |
108 | - |
109 | - report_line['item'] = '' |
110 | - report_line['qty_ordered'] = '' |
111 | - report_line['uom'] = '' |
112 | -# if backorder and inline_in.get('state') != 'done': |
113 | -# report_line['qty_received'] = other_in.get('product_qty', '') |
114 | -# report_line['qty_backordered'] = inline_in.get('product_qty', '') |
115 | -# else: |
116 | - report_line['qty_received'] = other_in.get('product_qty','') |
117 | - report_line['qty_backordered'] = '' |
118 | - report_line['in'] = other_in.get('name','') |
119 | - report_line['unit_price'] = line.price_unit or '' |
120 | - if other_in.get('price_unit') and other_in.get('price_unit') <> multiplier: |
121 | - report_line['in_unit_price'] = other_in.get('price_unit') |
122 | - else: |
123 | - report_line['in_unit_price'] = '' |
124 | - report_line['destination'] = analytic_lines[0].get('destination') |
125 | - report_line['cost_centre'] = analytic_lines[0].get('cost_center') |
126 | - if other_in.get('state') != 'done': |
127 | - report_line['in_unit_price'] = '' |
128 | - report_lines.append(report_line) |
129 | - |
130 | - # sort the list for presentation in excel |
131 | - sorted_lines = sorted(report_lines, key=lambda k: k['sort_key']) |
132 | - return sorted_lines |
133 | - |
134 | + same_product_same_uom = [] |
135 | + same_product = [] |
136 | + other_product = [] |
137 | + |
138 | + for inl in in_lines: |
139 | + if inl.get('product_id') and inl.get('product_id') == line.product_id.id: |
140 | + if inl.get('product_uom') and inl.get('product_uom') == line.product_uom.id: |
141 | + same_product_same_uom.append(inl) |
142 | + else: |
143 | + same_product.append(inl) |
144 | + else: |
145 | + other_product.append(inl) |
146 | + |
147 | + first_line = True |
148 | + # Display information of the initial reception |
149 | + if not same_product_same_uom: |
150 | + report_line = { |
151 | + 'item': line.line_number or '', |
152 | + 'code': line.product_id.default_code or '', |
153 | + 'description': line.product_id.name or '', |
154 | + 'qty_ordered': line.product_qty or '', |
155 | + 'uom': line.product_uom.name or '', |
156 | + 'qty_received': '0.00', |
157 | + 'in': '', |
158 | + 'qty_backordered': '', |
159 | + 'destination': analytic_lines[0].get('destination'), |
160 | + 'cost_centre': analytic_lines[0].get('cost_center'), |
161 | + 'unit_price': line.price_unit or '', |
162 | + 'in_unit_price': '', |
163 | + } |
164 | + report_lines.append(report_line) |
165 | + report_lines.extend(self.printAnalyticLines(analytic_lines)) |
166 | + first_line = False |
167 | + |
168 | + for spsul in same_product_same_uom: |
169 | + report_line = { |
170 | + 'item': first_line and line.line_number or '', |
171 | + 'code': first_line and line.product_id.default_code or '', |
172 | + 'description': first_line and line.product_id.name or '', |
173 | + 'qty_ordered': first_line and line.product_qty or '', |
174 | + 'uom': line.product_uom.name or '', |
175 | + 'qty_received': spsul.get('state') == 'done' and spsul.get('product_qty', '') or '0.00', |
176 | + 'in': spsul.get('name', '') or '', |
177 | + 'qty_backordered': '', |
178 | + 'destination': analytic_lines[0].get('destination'), |
179 | + 'cost_centre': analytic_lines[0].get('cost_center'), |
180 | + 'unit_price': line.price_unit or '', |
181 | + 'in_unit_price': spsul.get('price_unit'), |
182 | + } |
183 | + |
184 | + report_lines.append(report_line) |
185 | + |
186 | + if first_line: |
187 | + if spsul.get('backorder_id') and spsul.get('state') != 'done': |
188 | + report_line['qty_backordered'] = spsul.get('product_qty', '') |
189 | + report_lines.extend(self.printAnalyticLines(analytic_lines)) |
190 | + first_line = False |
191 | + |
192 | + for spl in same_product: |
193 | + report_line = { |
194 | + 'item': first_line and line.line_number or '', |
195 | + 'code': first_line and line.product_id.default_code or '', |
196 | + 'description': first_line and line.product_id.name or '', |
197 | + 'qty_ordered': first_line and line.product_qty or '', |
198 | + 'uom': uom_obj.read(self.cr, self.uid, spl.get('product_uom'), ['name'])['name'], |
199 | + 'qty_received': spl.get('state') == 'done' and spl.get('product_qty', '') or '0.00', |
200 | + 'in': spl.get('name', '') or '', |
201 | + 'qty_backordered': '', |
202 | + 'destination': analytic_lines[0].get('destination'), |
203 | + 'cost_centre': analytic_lines[0].get('cost_center'), |
204 | + 'unit_price': line.price_unit or '', |
205 | + 'in_unit_price': spl.get('price_unit'), |
206 | + } |
207 | + report_lines.append(report_line) |
208 | + |
209 | + if first_line: |
210 | + if spl.get('backorder_id') and spl.get('state') != 'done': |
211 | + report_line['qty_backordered'] = spl.get('product_qty', '') |
212 | + report_lines.extend(self.printAnalyticLines(analytic_lines)) |
213 | + first_line = False |
214 | + |
215 | + for ol in other_product: |
216 | + prod_brw = prod_obj.browse(self.cr, self.uid, ol.get('product_id')) |
217 | + report_line = { |
218 | + 'item': line.line_number or '', |
219 | + 'code': prod_brw.default_code or '', |
220 | + 'description': prod_brw.name or '', |
221 | + 'qty_ordered': '', |
222 | + 'uom': uom_obj.read(self.cr, self.uid, ol.get('product_uom'), ['name'])['name'], |
223 | + 'qty_received': ol.get('state') == 'done' and ol.get('product_qty', '') or '0.00', |
224 | + 'in': ol.get('name', '') or '', |
225 | + 'qty_backordered': '', |
226 | + 'destination': analytic_lines[0].get('destination'), |
227 | + 'cost_centre': analytic_lines[0].get('cost_center'), |
228 | + 'unit_price': line.price_unit or '', |
229 | + 'in_unit_price': ol.get('price_unit'), |
230 | + } |
231 | + report_lines.append(report_line) |
232 | + |
233 | + return report_lines |
234 | + |
235 | def getAnalyticLines(self,po_line): |
236 | ccdl_obj = self.pool.get('cost.center.distribution.line') |
237 | if po_line.analytic_distribution_id.id: |
238 | @@ -501,37 +534,25 @@ |
239 | if not dist_lines: |
240 | dist_lines = [{'cost_center': '','destination': ''}] |
241 | return dist_lines |
242 | - |
243 | - def getInlineIN(self,po_line_id): |
244 | - sm_obj = self.pool.get('stock.move') |
245 | - self.cr.execute(''' select sm.id, sp.name, sm.product_qty, sm.product_uom, sm.price_unit, sm.state, sp.backorder_id |
246 | - from stock_move sm, stock_picking sp |
247 | - where sm.purchase_line_id = %s |
248 | - and sm.type = 'in' |
249 | - and sm.picking_id = sp.id |
250 | - order by sp.name, sm.id asc limit 1''' % (po_line_id)) |
251 | - row = self.cr.dictfetchall() |
252 | - if row: |
253 | - return row[0] |
254 | - else: |
255 | - return {} |
256 | - |
257 | - |
258 | - def getOtherINs(self,po_line_id,exclude_id): |
259 | - sm_obj = self.pool.get('stock.move') |
260 | - self.cr.execute(''' select sm.id, sp.name, sm.product_qty, sm.product_id, sm.product_uom, sm.price_unit, sm.state, sm.picking_id |
261 | - from stock_move sm, stock_picking sp |
262 | - where sm.purchase_line_id = %s |
263 | - and sm.type = 'in' |
264 | - and sm.picking_id = sp.id |
265 | - and sm.id <> %s |
266 | - order by sp.name, sm.id asc''' % (po_line_id,exclude_id)) |
267 | - rows = self.cr.dictfetchall() |
268 | - if rows: |
269 | - return rows |
270 | - else: |
271 | - return [] |
272 | - |
273 | + |
274 | + def getAllLineIN(self, po_line_id): |
275 | + self.cr.execute(''' |
276 | + SELECT |
277 | + sm.id, sp.name, sm.product_id, sm.product_qty, |
278 | + sm.product_uom, sm.price_unit, sm.state, |
279 | + sp.backorder_id, sm.picking_id |
280 | + FROM |
281 | + stock_move sm, stock_picking sp |
282 | + WHERE |
283 | + sm.purchase_line_id = %s |
284 | + AND |
285 | + sm.type = 'in' |
286 | + AND |
287 | + sm.picking_id = sp.id |
288 | + ORDER BY |
289 | + sp.name, sm.id asc''', tuple([po_line_id])) |
290 | + return self.cr.dictfetchall() |
291 | + |
292 | def getReportHeaderLine1(self): |
293 | return self.datas.get('report_header')[0] |
294 | |
295 | @@ -553,8 +574,7 @@ |
296 | 'getHeaderLine2': self.getHeaderLine2, |
297 | 'getReportHeaderLine1': self.getReportHeaderLine1, |
298 | 'getReportHeaderLine2': self.getReportHeaderLine2, |
299 | - 'getInlineIN': self.getInlineIN, |
300 | - 'getOtherINs': self.getOtherINs, |
301 | + 'getAllLineIN': self.getAllLineIN, |
302 | 'getPOLines': self.getPOLines, |
303 | 'getPOLineHeaders': self.getPOLineHeaders, |
304 | 'getRunParms': self.getRunParms, |