Merge lp:~unifield-team/unifield-addons/hooks-action-ship-create into lp:unifield-addons
- hooks-action-ship-create
- Merge into trunk
Proposed by
Patrick Amstutz
Status: | Merged |
---|---|
Merged at revision: | 4493 |
Proposed branch: | lp:~unifield-team/unifield-addons/hooks-action-ship-create |
Merge into: | lp:unifield-addons |
Diff against target: |
219 lines (+125/-56) 1 file modified
sale/sale.py (+125/-56) |
To merge this branch: | bzr merge lp:~unifield-team/unifield-addons/hooks-action-ship-create |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
UniField Dev Team | Pending | ||
Review via email: mp+76231@code.launchpad.net |
Commit message
Description of the change
To post a comment you must log in.
- 4493. By Quentin THEURET @Amaris
-
Add hook of return packing wizard
- 4494. By Quentin THEURET @Amaris
-
Add hook of return packing wizard
- 4495. By Quentin THEURET @Amaris
-
Add hook on procurement order
- 4496. By Quentin THEURET @Amaris
-
UF-370 [IMP] Added a hook on purchase_
order.action_ picking_ create - 4497. By Quentin THEURET @Amaris
-
[REV] Reverted to the revision 4492
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'sale/sale.py' |
2 | --- sale/sale.py 2011-07-07 10:50:50 +0000 |
3 | +++ sale/sale.py 2011-09-21 14:46:31 +0000 |
4 | @@ -649,14 +649,76 @@ |
5 | if notcanceled: |
6 | return False |
7 | return canceled |
8 | - |
9 | - def action_ship_create(self, cr, uid, ids, *args): |
10 | + |
11 | + def _hook_ship_create_stock_move(self, cr, uid, ids, context=None, *args, **kwargs): |
12 | + ''' |
13 | + Please copy this to your module's method also. |
14 | + This hook belongs to the action_ship_create method from sale>sale.py |
15 | + |
16 | + - allow to modify the data for stock move creation |
17 | + ''' |
18 | + move_data = kwargs['move_data'] |
19 | + return move_data |
20 | + |
21 | + def _hook_ship_create_procurement_order(self, cr, uid, ids, context=None, *args, **kwargs): |
22 | + ''' |
23 | + Please copy this to your module's method also. |
24 | + This hook belongs to the action_ship_create method from sale>sale.py |
25 | + |
26 | + - allow to modify the data for procurement order creation |
27 | + ''' |
28 | + proc_data = kwargs['proc_data'] |
29 | + return proc_data |
30 | + |
31 | + def _hook_ship_create_stock_picking(self, cr, uid, ids, context=None, *args, **kwargs): |
32 | + ''' |
33 | + Please copy this to your module's method also. |
34 | + This hook belongs to the action_ship_create method from sale>sale.py |
35 | + |
36 | + - allow to modify the data for stock picking creation |
37 | + ''' |
38 | + picking_data = kwargs['picking_data'] |
39 | + return picking_data |
40 | + |
41 | + def _hook_ship_create_execute_picking_workflow(self, cr, uid, ids, context=None, *args, **kwargs): |
42 | + ''' |
43 | + Please copy this to your module's method also. |
44 | + This hook belongs to the action_ship_create method from sale>sale.py |
45 | + |
46 | + - allow to avoid the stock picking workflow execution |
47 | + ''' |
48 | + picking_id = kwargs['picking_id'] |
49 | + return picking_id |
50 | + |
51 | + def _hook_ship_create_execute_specific_code_01(self, cr, uid, ids, context=None, *args, **kwargs): |
52 | + ''' |
53 | + Please copy this to your module's method also. |
54 | + This hook belongs to the action_ship_create method from sale>sale.py |
55 | + |
56 | + - allow to execute specific code at position 01 |
57 | + ''' |
58 | + pass |
59 | + |
60 | + def _hook_ship_create_line_condition(self, cr, uid, ids, context=None, *args, **kwargs): |
61 | + ''' |
62 | + Please copy this to your module's method also. |
63 | + This hook belongs to the action_ship_create method from sale>sale.py |
64 | + |
65 | + - allow to customize the execution condition |
66 | + ''' |
67 | + line = kwargs['line'] |
68 | + result = line.product_id and line.product_id.product_tmpl_id.type in ('product', 'consu') |
69 | + return result |
70 | + |
71 | + def action_ship_create(self, cr, uid, ids, context=None, *args): |
72 | + if context is None: |
73 | + context = {} |
74 | wf_service = netsvc.LocalService("workflow") |
75 | picking_id = False |
76 | move_obj = self.pool.get('stock.move') |
77 | proc_obj = self.pool.get('procurement.order') |
78 | company = self.pool.get('res.users').browse(cr, uid, uid).company_id |
79 | - for order in self.browse(cr, uid, ids, context={}): |
80 | + for order in self.browse(cr, uid, ids, context=context): |
81 | proc_ids = [] |
82 | output_id = order.shop_id.warehouse_id.lot_output_id.id |
83 | picking_id = False |
84 | @@ -668,63 +730,69 @@ |
85 | if line.state == 'done': |
86 | continue |
87 | move_id = False |
88 | - if line.product_id and line.product_id.product_tmpl_id.type in ('product', 'consu'): |
89 | + if self._hook_ship_create_line_condition(cr, uid, ids, context=context, line=line,): |
90 | location_id = order.shop_id.warehouse_id.lot_stock_id.id |
91 | if not picking_id: |
92 | pick_name = self.pool.get('ir.sequence').get(cr, uid, 'stock.picking.out') |
93 | - picking_id = self.pool.get('stock.picking').create(cr, uid, { |
94 | - 'name': pick_name, |
95 | - 'origin': order.name, |
96 | - 'type': 'out', |
97 | - 'state': 'auto', |
98 | - 'move_type': order.picking_policy, |
99 | - 'sale_id': order.id, |
100 | - 'address_id': order.partner_shipping_id.id, |
101 | - 'note': order.note, |
102 | - 'invoice_state': (order.order_policy=='picking' and '2binvoiced') or 'none', |
103 | - 'company_id': order.company_id.id, |
104 | - }) |
105 | - move_id = self.pool.get('stock.move').create(cr, uid, { |
106 | - 'name': line.name[:64], |
107 | - 'picking_id': picking_id, |
108 | - 'product_id': line.product_id.id, |
109 | - 'date': date_planned, |
110 | - 'date_expected': date_planned, |
111 | - 'product_qty': line.product_uom_qty, |
112 | - 'product_uom': line.product_uom.id, |
113 | - 'product_uos_qty': line.product_uos_qty, |
114 | - 'product_uos': (line.product_uos and line.product_uos.id)\ |
115 | - or line.product_uom.id, |
116 | - 'product_packaging': line.product_packaging.id, |
117 | - 'address_id': line.address_allotment_id.id or order.partner_shipping_id.id, |
118 | - 'location_id': location_id, |
119 | - 'location_dest_id': output_id, |
120 | - 'sale_line_id': line.id, |
121 | - 'tracking_id': False, |
122 | - 'state': 'draft', |
123 | - #'state': 'waiting', |
124 | - 'note': line.notes, |
125 | - 'company_id': order.company_id.id, |
126 | - }) |
127 | + picking_data = {'name': pick_name, |
128 | + 'origin': order.name, |
129 | + 'type': 'out', |
130 | + 'state': 'auto', |
131 | + 'move_type': order.picking_policy, |
132 | + 'sale_id': order.id, |
133 | + 'address_id': order.partner_shipping_id.id, |
134 | + 'note': order.note, |
135 | + 'invoice_state': (order.order_policy=='picking' and '2binvoiced') or 'none', |
136 | + 'company_id': order.company_id.id, |
137 | + } |
138 | + picking_data = self._hook_ship_create_stock_picking(cr, uid, ids, context=context, picking_data=picking_data, order=order,) |
139 | + picking_id = self.pool.get('stock.picking').create(cr, uid, picking_data, context=context) |
140 | + |
141 | + move_data = {'name': line.name[:64], |
142 | + 'picking_id': picking_id, |
143 | + 'product_id': line.product_id.id, |
144 | + 'date': date_planned, |
145 | + 'date_expected': date_planned, |
146 | + 'product_qty': line.product_uom_qty, |
147 | + 'product_uom': line.product_uom.id, |
148 | + 'product_uos_qty': line.product_uos_qty, |
149 | + 'product_uos': (line.product_uos and line.product_uos.id)\ |
150 | + or line.product_uom.id, |
151 | + 'product_packaging': line.product_packaging.id, |
152 | + 'address_id': line.address_allotment_id.id or order.partner_shipping_id.id, |
153 | + 'location_id': location_id, |
154 | + 'location_dest_id': output_id, |
155 | + 'sale_line_id': line.id, |
156 | + 'tracking_id': False, |
157 | + 'state': 'draft', |
158 | + #'state': 'waiting', |
159 | + 'note': line.notes, |
160 | + 'company_id': order.company_id.id, |
161 | + } |
162 | + |
163 | + # hook for stock move data modification |
164 | + move_data = self._hook_ship_create_stock_move(cr, uid, ids, context=context, move_data=move_data, line=line, order=order,) |
165 | + move_id = self.pool.get('stock.move').create(cr, uid, move_data, context=context) |
166 | |
167 | if line.product_id: |
168 | - proc_id = self.pool.get('procurement.order').create(cr, uid, { |
169 | - 'name': line.name, |
170 | - 'origin': order.name, |
171 | - 'date_planned': date_planned, |
172 | - 'product_id': line.product_id.id, |
173 | - 'product_qty': line.product_uom_qty, |
174 | - 'product_uom': line.product_uom.id, |
175 | - 'product_uos_qty': (line.product_uos and line.product_uos_qty)\ |
176 | - or line.product_uom_qty, |
177 | - 'product_uos': (line.product_uos and line.product_uos.id)\ |
178 | - or line.product_uom.id, |
179 | - 'location_id': order.shop_id.warehouse_id.lot_stock_id.id, |
180 | - 'procure_method': line.type, |
181 | - 'move_id': move_id, |
182 | - 'property_ids': [(6, 0, [x.id for x in line.property_ids])], |
183 | - 'company_id': order.company_id.id, |
184 | - }) |
185 | + proc_data = {'name': line.name, |
186 | + 'origin': order.name, |
187 | + 'date_planned': date_planned, |
188 | + 'product_id': line.product_id.id, |
189 | + 'product_qty': line.product_uom_qty, |
190 | + 'product_uom': line.product_uom.id, |
191 | + 'product_uos_qty': (line.product_uos and line.product_uos_qty)\ |
192 | + or line.product_uom_qty, |
193 | + 'product_uos': (line.product_uos and line.product_uos.id)\ |
194 | + or line.product_uom.id, |
195 | + 'location_id': order.shop_id.warehouse_id.lot_stock_id.id, |
196 | + 'procure_method': line.type, |
197 | + 'move_id': move_id, |
198 | + 'property_ids': [(6, 0, [x.id for x in line.property_ids])], |
199 | + 'company_id': order.company_id.id, |
200 | + } |
201 | + proc_data = self._hook_ship_create_procurement_order(cr, uid, ids, context=context, proc_data=proc_data, line=line,) |
202 | + proc_id = self.pool.get('procurement.order').create(cr, uid, proc_data) |
203 | proc_ids.append(proc_id) |
204 | self.pool.get('sale.order.line').write(cr, uid, [line.id], {'procurement_id': proc_id}) |
205 | if order.state == 'shipping_except': |
206 | @@ -739,11 +807,12 @@ |
207 | |
208 | val = {} |
209 | |
210 | - if picking_id: |
211 | + if self._hook_ship_create_execute_picking_workflow(cr, uid, ids, context=context, picking_id=picking_id,): |
212 | wf_service.trg_validate(uid, 'stock.picking', picking_id, 'button_confirm', cr) |
213 | |
214 | for proc_id in proc_ids: |
215 | wf_service.trg_validate(uid, 'procurement.order', proc_id, 'button_confirm', cr) |
216 | + self._hook_ship_create_execute_specific_code_01(cr, uid, ids, context=context, order=order, proc_id=proc_id,) |
217 | |
218 | if order.state == 'shipping_except': |
219 | val['state'] = 'progress' |