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