Merge lp:~openbig/bigconsulting/packing_barcode_workflow into lp:bigconsulting

Proposed by gpa(OpenERP)
Status: Merged
Merged at revision: 78
Proposed branch: lp:~openbig/bigconsulting/packing_barcode_workflow
Merge into: lp:bigconsulting
Diff against target: 365 lines (+108/-40)
7 files modified
packing_barcode_check/__terp__.py (+3/-1)
packing_barcode_check/packing_barcode_check.py (+37/-7)
packing_barcode_check/packing_barcode_check_view.xml (+6/-3)
packing_barcode_check/packing_barcode_check_wizard.xml (+1/-8)
packing_barcode_check/packing_barcode_check_workflow.xml (+26/-0)
packing_barcode_check/wizard/scan_product.py (+11/-3)
stock_minimum_calculator/wizard/stock_order_point_calculator.py (+24/-18)
To merge this branch: bzr merge lp:~openbig/bigconsulting/packing_barcode_workflow
Reviewer Review Type Date Requested Status
openbig Pending
Review via email: mp+33083@code.launchpad.net

This proposal supersedes a proposal from 2010-08-19.

Description of the change

Added workflow in the packing_barcode_check

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'packing_barcode_check/__terp__.py'
2--- packing_barcode_check/__terp__.py 2010-07-26 15:12:49 +0000
3+++ packing_barcode_check/__terp__.py 2010-08-19 05:53:05 +0000
4@@ -31,9 +31,11 @@
5 "license" : "GPL-3",
6 "depends" : ["base","product","stock"],
7 "init_xml" : [],
8- "update_xml" : ["packing_barcode_check_view.xml",
9+ "update_xml" : [
10 "packing_barcode_check_wizard.xml",
11 "packing_barcode_check_report.xml",
12+ "packing_barcode_check_view.xml",
13+ "packing_barcode_check_workflow.xml",
14 ],
15 "active": False,
16 "installable": True
17
18=== modified file 'packing_barcode_check/packing_barcode_check.py'
19--- packing_barcode_check/packing_barcode_check.py 2010-08-17 07:47:09 +0000
20+++ packing_barcode_check/packing_barcode_check.py 2010-08-19 05:53:05 +0000
21@@ -31,23 +31,31 @@
22 def _compute_quantity(self, cr, uid, ids, fieldnames, args, context=None):
23 res = {}
24 for obj in self.browse(cr, uid, ids, context=context):
25- total_quantity = sum(to_be_id.quantity for to_be_id in obj.tobe_scan_ids)
26- scanned_quantity = sum(to_be_id.scan_quantity for to_be_id in obj.tobe_scan_ids)
27+ total_quantity = sum(move_id.product_qty for move_id in obj.move_lines)
28+ scanned_quantity = sum(scan.scan_quantity for scan in obj.scaned_ids)
29 res[obj.id] = {
30 'total_quantity' : total_quantity,
31 'scanned_quantity' : scanned_quantity,
32 'to_be_scanned_quantity' : total_quantity - scanned_quantity,
33 }
34-
35+
36 return res
37
38-
39 _columns = {
40 'total_quantity':fields.function(_compute_quantity, method=True, string='Total Quantity', multi='quantity'),
41 'scanned_quantity': fields.function(_compute_quantity, method=True, string='Scanned Quantity', multi='quantity'),
42 'to_be_scanned_quantity':fields.function(_compute_quantity, method=True, string='Unscanned Quantity', multi='quantity'),
43 'tobe_scan_ids':fields.one2many('tobe.scanned.stock', 'tobe_picking_id', 'To Be'),
44 'scaned_ids':fields.one2many('scanned.stock', 'scanned_picking_id', 'Scanned Picking',),
45+ 'state': fields.selection([
46+ ('draft', 'Draft'),
47+ ('auto', 'Waiting'),
48+ ('confirmed', 'Confirmed'),
49+ ('assigned', 'Available'),
50+ ('scanned', 'Scanned'),
51+ ('done', 'Done'),
52+ ('cancel', 'Cancelled'),
53+ ], 'Status', readonly=True, select=True),
54 }
55 _defaults = {
56 'scanned_quantity' : lambda *a:0.0,
57@@ -58,6 +66,18 @@
58 move_ids = move_obj.search(cr, uid, [('picking_id','=',ids[0])])
59 move_obj.write(cr, uid, move_ids, {'scaned_qty':0.0}, context)
60 return True
61+
62+ def test_scanned(self, cr, uid, ids, context={}):
63+ for pick in self.browse(cr, uid, ids, context=context):
64+ if pick.tobe_scan_ids:
65+ return False
66+ return True
67+
68+ def action_scanned_wkf(self, cr, uid, ids, context={}):
69+ for pick in self.browse(cr, uid, ids, context=context):
70+ if not pick.tobe_scan_ids:
71+ self.write(cr, uid, ids, {'state': 'scanned'})
72+ return True
73
74 stock_picking()
75
76@@ -65,11 +85,19 @@
77 _inherit = "stock.move"
78 _columns = {
79 'scaned_qty':fields.float("Scanned Qty"),
80+ 'unscaned_qty':fields.float("Unscanned Qty"),
81 }
82
83 _defaults = {
84 'scaned_qty' : lambda *a:0.0,
85 }
86+
87+ def onchange_quantity(self, cr, uid, ids, product_id, product_qty, product_uom, product_uos):
88+
89+ result = super(stock_move, self).onchange_quantity(cr, uid, ids, product_id, product_qty, product_uom, product_uos)
90+ if product_id:
91+ result['value']['unscaned_qty'] = product_qty
92+ return result
93 stock_move()
94
95 class tobe_scanned_stock(osv.osv):
96@@ -80,7 +108,8 @@
97 'product_name':fields.many2one('product.product','Product Name', size=64),
98 'lot_number':fields.many2one('stock.production.lot','Lot Number', size=64),
99 'quantity':fields.float("Quantity"),
100- 'scan_quantity':fields.float("Scan Quantity"),
101+ 'scan_quantity':fields.float("Scanned Quantity"),
102+ 'unscan_quantity':fields.float("Unscanned Quantity"),
103 }
104
105 def init(self, cr):
106@@ -92,6 +121,7 @@
107 l.picking_id AS tobe_picking_id,
108 sum(l.scaned_qty) AS scan_quantity,
109 sum(l.product_qty) AS quantity,
110+ sum(l.unscaned_qty) AS unscan_quantity,
111 l.prodlot_id AS lot_number,
112 l.product_id AS product_name
113 FROM
114@@ -112,7 +142,7 @@
115 'product_name':fields.many2one('product.product','Product Name', size=64),
116 'lot_number':fields.many2one('stock.production.lot','Lot Number', size=64),
117 'quantity':fields.float("Quantity"),
118- 'scan_quantity':fields.float("Scan Quantity"),
119+ 'scan_quantity':fields.float("Scanned Quantity"),
120 }
121
122 def init(self, cr):
123@@ -129,7 +159,7 @@
124 FROM
125 stock_move l
126 WHERE
127- l.scaned_qty = l.product_qty
128+ l.scaned_qty > 0
129 GROUP BY
130 l.product_id,l.prodlot_id,l.picking_id, l.id
131 )
132
133=== modified file 'packing_barcode_check/packing_barcode_check_view.xml'
134--- packing_barcode_check/packing_barcode_check_view.xml 2010-08-17 07:26:17 +0000
135+++ packing_barcode_check/packing_barcode_check_view.xml 2010-08-19 05:53:05 +0000
136@@ -38,7 +38,7 @@
137 <field name="backorder_id" select="2" readonly="1"/>
138 <field name="origin" select="2" readonly="1"/>
139 <label string=""/>
140- <button name="button_reset" string="Reset" type="object"/>
141+ <button name="button_reset" states="assigned" string="Reset" type="object"/>
142 </group>
143 <notebook colspan="4">
144 <page string="Scanning Info">
145@@ -48,7 +48,7 @@
146 <field name="product_name"/>
147 <field name="lot_number"/>
148 <field name="quantity"/>
149- <field name="scan_quantity"/>
150+ <field name="unscan_quantity"/>
151 </tree>
152 </field>
153 <field name="scaned_ids" nolabel="1">
154@@ -66,6 +66,8 @@
155 <button name="draft_validate" states="draft" string="Process Now" type="object"/>
156 <button name="action_assign" states="confirmed" string="Check Availability" type="object"/>
157 <button name="force_assign" states="confirmed" string="Force Availability" type="object"/>
158+ <button name="%(id_scan_product)d" states="assigned" string="Scan Packing" type="action"/>
159+ <button name="%(stock.partial_picking)d" states="scanned" string="Packing Done" type="action"/>
160 <button name="button_cancel" states="assigned,confirmed,draft" string="Cancel"/>
161 </group>
162 </page>
163@@ -104,11 +106,12 @@
164 <field name="arch" type="xml">
165 <xpath expr="//field[@name='product_qty']" position="after">
166 <field name="scaned_qty"/>
167+ <field name="unscaned_qty"/>
168 </xpath>
169 </field>
170 </record>
171
172- <wizard id="act_selct_picking_open_form" model="stock.picking" name="select.picking" string="Select picking"/>
173+ <wizard id="act_selct_picking_open_form" model="stock.picking" name="select.picking" menu="False" string="Select picking"/>
174 <menuitem action="act_selct_picking_open_form" id="menu_act_selct_picking_open_form" parent="stock.menu_stock_root" type="wizard"/>
175
176 </data>
177
178=== modified file 'packing_barcode_check/packing_barcode_check_wizard.xml'
179--- packing_barcode_check/packing_barcode_check_wizard.xml 2010-07-26 15:12:49 +0000
180+++ packing_barcode_check/packing_barcode_check_wizard.xml 2010-08-19 05:53:05 +0000
181@@ -1,18 +1,11 @@
182 <?xml version="1.0" encoding="utf-8"?>
183 <openerp>
184 <data>
185- <wizard
186- string="Select Picking Wizard"
187- model="stock.picking"
188- name="select.picking"
189- menu="False"
190- id="id_select_picking"/>
191-
192 <wizard
193 string="Scan Product"
194 model="stock.picking"
195 name="scan.product"
196- menu="True"
197+ menu="False"
198 id="id_scan_product"/>
199
200 </data>
201
202=== added file 'packing_barcode_check/packing_barcode_check_workflow.xml'
203--- packing_barcode_check/packing_barcode_check_workflow.xml 1970-01-01 00:00:00 +0000
204+++ packing_barcode_check/packing_barcode_check_workflow.xml 2010-08-19 05:53:05 +0000
205@@ -0,0 +1,26 @@
206+<?xml version="1.0" encoding="utf-8"?>
207+<openerp>
208+ <data>
209+
210+ <record id="act_scanned" model="workflow.activity">
211+ <field name="wkf_id" ref="stock.wkf_picking"/>
212+ <field name="name">scanned</field>
213+ <field name="kind">function</field>
214+ <field name="action">action_scanned_wkf()</field>
215+ </record>
216+
217+ <record id="trans_scanned_move" model="workflow.transition">
218+ <field name="act_from" ref="stock.act_assigned"/>
219+ <field name="act_to" ref="act_scanned"/>
220+ <field name="condition">test_scanned()</field>
221+ <field name="signal">button_scanned</field>
222+ </record>
223+
224+ <record id="stock.trans_scanned_assigned_move" model="workflow.transition">
225+ <field name="act_from" ref="act_scanned"/>
226+ <field name="act_to" ref="stock.act_move"/>
227+ <field name="signal">button_done</field>
228+ </record>
229+
230+ </data>
231+</openerp>
232
233=== modified file 'packing_barcode_check/wizard/scan_product.py'
234--- packing_barcode_check/wizard/scan_product.py 2010-08-13 14:17:17 +0000
235+++ packing_barcode_check/wizard/scan_product.py 2010-08-19 05:53:05 +0000
236@@ -22,6 +22,7 @@
237 import wizard
238 import pooler
239 import time
240+import netsvc
241 from tools.translate import _
242 from osv import osv
243
244@@ -61,11 +62,15 @@
245 raise osv.except_osv(_('Warning!'),
246 _('Unscanned quantity does not match with the product packaging quantity'))
247
248- stock_move_obj.write(cr, uid, [move_id],{'scaned_qty':move_data.scaned_qty+quantity}, context=context)
249+ stock_move_obj.write(cr, uid, [move_id],{'scaned_qty':move_data.scaned_qty+quantity, 'unscaned_qty':move_data.unscaned_qty-quantity}, context=context)
250+ wkf_service = netsvc.LocalService("workflow")
251+ wkf_service.trg_validate(uid, 'stock.picking', picking_id[0], 'button_scanned', cr)
252+
253 return 'init'
254 else:
255 raise osv.except_osv(_('Warning!'),
256 _('Product does not belongs to this picking or already scanned.'))
257+
258 return {}
259
260 scan_product_lot_form = """<?xml version="1.0"?>
261@@ -102,9 +107,12 @@
262 if check_qty < quantity:
263 raise osv.except_osv(_('Warning!'),
264 _('Unscanned quantity does not match with the product packaging quantity'))
265- move_obj.write(cr, uid, [stock_move_obj.id],{'scaned_qty':stock_move_obj.scaned_qty+quantity}, context=context)
266+ move_obj.write(cr, uid, [stock_move_obj.id],{'scaned_qty':stock_move_obj.scaned_qty+quantity,'unscaned_qty':stock_move_obj.unscaned_qty-quantity}, context=context)
267+ wkf_service = netsvc.LocalService("workflow")
268+ wkf_service.trg_validate(uid, 'stock.picking', picking_ids[0], 'button_scanned', cr)
269+
270 call_product_scan = 2
271- if stock_move_obj.product_qty >= stock_move_obj.scaned_qty+1:
272+ if stock_move_obj.product_qty >= stock_move_obj.scaned_qty+quantity:
273 call_product_scan = 1
274 break
275 if call_product_scan == 1:
276
277=== modified file 'stock_minimum_calculator/wizard/stock_order_point_calculator.py'
278--- stock_minimum_calculator/wizard/stock_order_point_calculator.py 2010-08-17 04:44:06 +0000
279+++ stock_minimum_calculator/wizard/stock_order_point_calculator.py 2010-08-19 05:53:05 +0000
280@@ -215,7 +215,7 @@
281 # 1. Calculation of the date date start in one year later than current date
282 from_date = (datetime.now() - relativedelta(months=12)).strftime('%Y-%m-%d %H:%M:%S')
283 to_date = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
284-
285+
286 # 2.1 first find the all the product which fullfill the criteria of the 2.1
287 product_ids = product_obj.search(cr,uid,[('active','=',True),('type','=','product'),
288 ('procure_method','=','make_to_stock'),
289@@ -246,8 +246,7 @@
290 if seller_id.name.id == partner_id:
291 supplier_lead_time = seller_id.delay
292
293- stock_move_ids = stock_move_obj.search(cr, uid, [('product_id','=',filter_product_id)])
294-
295+ stock_move_ids = stock_move_obj.search(cr, uid, [('product_id','=',filter_product_id),('state','=','done')])
296 average_daily_consumption = 0.0
297 first_stock_move_ids = []
298 # Take the first input date of the stock move where stock move of incoming picking or stock move not have any picking
299@@ -258,16 +257,16 @@
300 first_stock_move_ids.append(first_stock_id)
301 else:
302 first_stock_move_ids.append(first_stock_id)
303-
304+
305 if first_stock_move_ids:
306 first_stock_move_id = first_stock_move_ids[0]
307 first_input = stock_move_obj.browse(cr, uid, first_stock_move_id, context=context).date_planned
308-
309+
310 # Case 1 if first input is less than from date
311 if first_input <= from_date:
312- consum_qty = _sale_consume_qty(self, cr, uid, from_date, to_date, 'done', context)
313+ consum_qty = _sale_consume_qty(self, cr, uid, filter_product_id, from_date, to_date, 'done', context)
314 refund_qty = _refund_qty(self, cr, uid, filter_product_id, from_date, to_date, ['out_refund','in_refund'], context)
315- open_sale_qty = _sale_open_qty(self, cr, uid, filter_product_id, from_date, to_date, ['manual','progress'], context)
316+ open_sale_qty = _sale_open_qty(self, cr, uid, filter_product_id, ['manual','progress'], context)
317 open_purchase_qty = _purchase_open_qty(self, cr, uid, filter_product_id, 'approved', context)
318 pur_diff_day = _date_diff(self, cr, uid, filter_product_id, from_date, to_date, context)
319 ### calculation of average_daily_consumption
320@@ -287,20 +286,26 @@
321 average_daily_consumption = (consum_qty - refund_qty + open_sale_qty - open_purchase_qty) / pur_diff_day
322 else:
323 open_sale_qty = _sale_open_qty(self, cr, uid, filter_product_id, ['manual','progress'], context)
324- open_purchase_qty = _purchase_open_qty(self, cr, uid, filter_product_id, 'approved', context)
325+ open_purchase_qty = _purchase_open_qty(self, cr, uid, filter_product_id, 'approved', context)
326+
327+ if open_purchase_qty == 0.0 or open_sale_qty == 0.0:
328+ continue
329
330 # calculation of first open purchase order date
331- open_purchase_ids = purchase_obj.search(cr,uid,[('state','=','approved')])
332- first_open_purchase_order = min(open_purchase_ids)
333- fst_open_pur_date = purchase_obj.browse(cr, uid, first_open_purchase_order, context=context).date_order
334+ open_purchase_ids = purchase_obj.search(cr,uid,[('state','=','approved')])
335+ if open_purchase_ids:
336+ first_open_purchase_order = min(open_purchase_ids)
337+ fst_open_pur_date = purchase_obj.browse(cr, uid, first_open_purchase_order, context=context).date_order
338
339- # Days difference between to date and first purchase date
340- pur_to_date = time.mktime(time.strptime(to_date,'%Y-%m-%d %H:%M:%S'))
341- pur_open_date = time.mktime(time.strptime(fst_open_pur_date,'%Y-%m-%d'))
342- pur_diff_day = (pur_to_date-pur_open_date)/(3600*24)
343-
344- if pur_diff_day>0:
345- average_daily_consumption = (open_sale_qty - open_purchase_qty)/pur_diff_day
346+ # Days difference between to date and first purchase date
347+ pur_diff_day = 0.0
348+ if fst_open_pur_date:
349+ pur_to_date = time.mktime(time.strptime(to_date,'%Y-%m-%d %H:%M:%S'))
350+ pur_open_date = time.mktime(time.strptime(fst_open_pur_date,'%Y-%m-%d'))
351+ pur_diff_day = (pur_to_date-pur_open_date)/(3600*24)
352+
353+ if pur_diff_day>0:
354+ average_daily_consumption = (open_sale_qty - open_purchase_qty)/pur_diff_day
355
356 ###### Calculation of plan_average_daily_consumption
357 plan_average_daily_consumption = 0.0
358@@ -327,6 +332,7 @@
359 min_rule_obj.unlink(cr, uid, [stock_rule_id],context=context)
360
361 mini_stock_rule_id = min_rule_obj.search(cr,uid,[('warehouse_id','=',data['form']['warehouse_id']),('product_id','=',filter_product_id)])
362+
363 if mini_stock_rule_id:
364 for stock_rule_id in mini_stock_rule_id:
365 min_rule_obj.write(cr, uid, [stock_rule_id],{'product_min_qty':product_min_qty,'product_max_qty':product_max_qty,},context=context)

Subscribers

People subscribed via source and target branches