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 | 649 | if notcanceled: | 649 | if notcanceled: |
6 | 650 | return False | 650 | return False |
7 | 651 | return canceled | 651 | return canceled |
10 | 652 | 652 | ||
11 | 653 | def action_ship_create(self, cr, uid, ids, *args): | 653 | def _hook_ship_create_stock_move(self, cr, uid, ids, context=None, *args, **kwargs): |
12 | 654 | ''' | ||
13 | 655 | Please copy this to your module's method also. | ||
14 | 656 | This hook belongs to the action_ship_create method from sale>sale.py | ||
15 | 657 | |||
16 | 658 | - allow to modify the data for stock move creation | ||
17 | 659 | ''' | ||
18 | 660 | move_data = kwargs['move_data'] | ||
19 | 661 | return move_data | ||
20 | 662 | |||
21 | 663 | def _hook_ship_create_procurement_order(self, cr, uid, ids, context=None, *args, **kwargs): | ||
22 | 664 | ''' | ||
23 | 665 | Please copy this to your module's method also. | ||
24 | 666 | This hook belongs to the action_ship_create method from sale>sale.py | ||
25 | 667 | |||
26 | 668 | - allow to modify the data for procurement order creation | ||
27 | 669 | ''' | ||
28 | 670 | proc_data = kwargs['proc_data'] | ||
29 | 671 | return proc_data | ||
30 | 672 | |||
31 | 673 | def _hook_ship_create_stock_picking(self, cr, uid, ids, context=None, *args, **kwargs): | ||
32 | 674 | ''' | ||
33 | 675 | Please copy this to your module's method also. | ||
34 | 676 | This hook belongs to the action_ship_create method from sale>sale.py | ||
35 | 677 | |||
36 | 678 | - allow to modify the data for stock picking creation | ||
37 | 679 | ''' | ||
38 | 680 | picking_data = kwargs['picking_data'] | ||
39 | 681 | return picking_data | ||
40 | 682 | |||
41 | 683 | def _hook_ship_create_execute_picking_workflow(self, cr, uid, ids, context=None, *args, **kwargs): | ||
42 | 684 | ''' | ||
43 | 685 | Please copy this to your module's method also. | ||
44 | 686 | This hook belongs to the action_ship_create method from sale>sale.py | ||
45 | 687 | |||
46 | 688 | - allow to avoid the stock picking workflow execution | ||
47 | 689 | ''' | ||
48 | 690 | picking_id = kwargs['picking_id'] | ||
49 | 691 | return picking_id | ||
50 | 692 | |||
51 | 693 | def _hook_ship_create_execute_specific_code_01(self, cr, uid, ids, context=None, *args, **kwargs): | ||
52 | 694 | ''' | ||
53 | 695 | Please copy this to your module's method also. | ||
54 | 696 | This hook belongs to the action_ship_create method from sale>sale.py | ||
55 | 697 | |||
56 | 698 | - allow to execute specific code at position 01 | ||
57 | 699 | ''' | ||
58 | 700 | pass | ||
59 | 701 | |||
60 | 702 | def _hook_ship_create_line_condition(self, cr, uid, ids, context=None, *args, **kwargs): | ||
61 | 703 | ''' | ||
62 | 704 | Please copy this to your module's method also. | ||
63 | 705 | This hook belongs to the action_ship_create method from sale>sale.py | ||
64 | 706 | |||
65 | 707 | - allow to customize the execution condition | ||
66 | 708 | ''' | ||
67 | 709 | line = kwargs['line'] | ||
68 | 710 | result = line.product_id and line.product_id.product_tmpl_id.type in ('product', 'consu') | ||
69 | 711 | return result | ||
70 | 712 | |||
71 | 713 | def action_ship_create(self, cr, uid, ids, context=None, *args): | ||
72 | 714 | if context is None: | ||
73 | 715 | context = {} | ||
74 | 654 | wf_service = netsvc.LocalService("workflow") | 716 | wf_service = netsvc.LocalService("workflow") |
75 | 655 | picking_id = False | 717 | picking_id = False |
76 | 656 | move_obj = self.pool.get('stock.move') | 718 | move_obj = self.pool.get('stock.move') |
77 | 657 | proc_obj = self.pool.get('procurement.order') | 719 | proc_obj = self.pool.get('procurement.order') |
78 | 658 | company = self.pool.get('res.users').browse(cr, uid, uid).company_id | 720 | company = self.pool.get('res.users').browse(cr, uid, uid).company_id |
80 | 659 | for order in self.browse(cr, uid, ids, context={}): | 721 | for order in self.browse(cr, uid, ids, context=context): |
81 | 660 | proc_ids = [] | 722 | proc_ids = [] |
82 | 661 | output_id = order.shop_id.warehouse_id.lot_output_id.id | 723 | output_id = order.shop_id.warehouse_id.lot_output_id.id |
83 | 662 | picking_id = False | 724 | picking_id = False |
84 | @@ -668,63 +730,69 @@ | |||
85 | 668 | if line.state == 'done': | 730 | if line.state == 'done': |
86 | 669 | continue | 731 | continue |
87 | 670 | move_id = False | 732 | move_id = False |
89 | 671 | if line.product_id and line.product_id.product_tmpl_id.type in ('product', 'consu'): | 733 | if self._hook_ship_create_line_condition(cr, uid, ids, context=context, line=line,): |
90 | 672 | location_id = order.shop_id.warehouse_id.lot_stock_id.id | 734 | location_id = order.shop_id.warehouse_id.lot_stock_id.id |
91 | 673 | if not picking_id: | 735 | if not picking_id: |
92 | 674 | pick_name = self.pool.get('ir.sequence').get(cr, uid, 'stock.picking.out') | 736 | pick_name = self.pool.get('ir.sequence').get(cr, uid, 'stock.picking.out') |
127 | 675 | picking_id = self.pool.get('stock.picking').create(cr, uid, { | 737 | picking_data = {'name': pick_name, |
128 | 676 | 'name': pick_name, | 738 | 'origin': order.name, |
129 | 677 | 'origin': order.name, | 739 | 'type': 'out', |
130 | 678 | 'type': 'out', | 740 | 'state': 'auto', |
131 | 679 | 'state': 'auto', | 741 | 'move_type': order.picking_policy, |
132 | 680 | 'move_type': order.picking_policy, | 742 | 'sale_id': order.id, |
133 | 681 | 'sale_id': order.id, | 743 | 'address_id': order.partner_shipping_id.id, |
134 | 682 | 'address_id': order.partner_shipping_id.id, | 744 | 'note': order.note, |
135 | 683 | 'note': order.note, | 745 | 'invoice_state': (order.order_policy=='picking' and '2binvoiced') or 'none', |
136 | 684 | 'invoice_state': (order.order_policy=='picking' and '2binvoiced') or 'none', | 746 | 'company_id': order.company_id.id, |
137 | 685 | 'company_id': order.company_id.id, | 747 | } |
138 | 686 | }) | 748 | picking_data = self._hook_ship_create_stock_picking(cr, uid, ids, context=context, picking_data=picking_data, order=order,) |
139 | 687 | move_id = self.pool.get('stock.move').create(cr, uid, { | 749 | picking_id = self.pool.get('stock.picking').create(cr, uid, picking_data, context=context) |
140 | 688 | 'name': line.name[:64], | 750 | |
141 | 689 | 'picking_id': picking_id, | 751 | move_data = {'name': line.name[:64], |
142 | 690 | 'product_id': line.product_id.id, | 752 | 'picking_id': picking_id, |
143 | 691 | 'date': date_planned, | 753 | 'product_id': line.product_id.id, |
144 | 692 | 'date_expected': date_planned, | 754 | 'date': date_planned, |
145 | 693 | 'product_qty': line.product_uom_qty, | 755 | 'date_expected': date_planned, |
146 | 694 | 'product_uom': line.product_uom.id, | 756 | 'product_qty': line.product_uom_qty, |
147 | 695 | 'product_uos_qty': line.product_uos_qty, | 757 | 'product_uom': line.product_uom.id, |
148 | 696 | 'product_uos': (line.product_uos and line.product_uos.id)\ | 758 | 'product_uos_qty': line.product_uos_qty, |
149 | 697 | or line.product_uom.id, | 759 | 'product_uos': (line.product_uos and line.product_uos.id)\ |
150 | 698 | 'product_packaging': line.product_packaging.id, | 760 | or line.product_uom.id, |
151 | 699 | 'address_id': line.address_allotment_id.id or order.partner_shipping_id.id, | 761 | 'product_packaging': line.product_packaging.id, |
152 | 700 | 'location_id': location_id, | 762 | 'address_id': line.address_allotment_id.id or order.partner_shipping_id.id, |
153 | 701 | 'location_dest_id': output_id, | 763 | 'location_id': location_id, |
154 | 702 | 'sale_line_id': line.id, | 764 | 'location_dest_id': output_id, |
155 | 703 | 'tracking_id': False, | 765 | 'sale_line_id': line.id, |
156 | 704 | 'state': 'draft', | 766 | 'tracking_id': False, |
157 | 705 | #'state': 'waiting', | 767 | 'state': 'draft', |
158 | 706 | 'note': line.notes, | 768 | #'state': 'waiting', |
159 | 707 | 'company_id': order.company_id.id, | 769 | 'note': line.notes, |
160 | 708 | }) | 770 | 'company_id': order.company_id.id, |
161 | 771 | } | ||
162 | 772 | |||
163 | 773 | # hook for stock move data modification | ||
164 | 774 | move_data = self._hook_ship_create_stock_move(cr, uid, ids, context=context, move_data=move_data, line=line, order=order,) | ||
165 | 775 | move_id = self.pool.get('stock.move').create(cr, uid, move_data, context=context) | ||
166 | 709 | 776 | ||
167 | 710 | if line.product_id: | 777 | if line.product_id: |
185 | 711 | proc_id = self.pool.get('procurement.order').create(cr, uid, { | 778 | proc_data = {'name': line.name, |
186 | 712 | 'name': line.name, | 779 | 'origin': order.name, |
187 | 713 | 'origin': order.name, | 780 | 'date_planned': date_planned, |
188 | 714 | 'date_planned': date_planned, | 781 | 'product_id': line.product_id.id, |
189 | 715 | 'product_id': line.product_id.id, | 782 | 'product_qty': line.product_uom_qty, |
190 | 716 | 'product_qty': line.product_uom_qty, | 783 | 'product_uom': line.product_uom.id, |
191 | 717 | 'product_uom': line.product_uom.id, | 784 | 'product_uos_qty': (line.product_uos and line.product_uos_qty)\ |
192 | 718 | 'product_uos_qty': (line.product_uos and line.product_uos_qty)\ | 785 | or line.product_uom_qty, |
193 | 719 | or line.product_uom_qty, | 786 | 'product_uos': (line.product_uos and line.product_uos.id)\ |
194 | 720 | 'product_uos': (line.product_uos and line.product_uos.id)\ | 787 | or line.product_uom.id, |
195 | 721 | or line.product_uom.id, | 788 | 'location_id': order.shop_id.warehouse_id.lot_stock_id.id, |
196 | 722 | 'location_id': order.shop_id.warehouse_id.lot_stock_id.id, | 789 | 'procure_method': line.type, |
197 | 723 | 'procure_method': line.type, | 790 | 'move_id': move_id, |
198 | 724 | 'move_id': move_id, | 791 | 'property_ids': [(6, 0, [x.id for x in line.property_ids])], |
199 | 725 | 'property_ids': [(6, 0, [x.id for x in line.property_ids])], | 792 | 'company_id': order.company_id.id, |
200 | 726 | 'company_id': order.company_id.id, | 793 | } |
201 | 727 | }) | 794 | proc_data = self._hook_ship_create_procurement_order(cr, uid, ids, context=context, proc_data=proc_data, line=line,) |
202 | 795 | proc_id = self.pool.get('procurement.order').create(cr, uid, proc_data) | ||
203 | 728 | proc_ids.append(proc_id) | 796 | proc_ids.append(proc_id) |
204 | 729 | self.pool.get('sale.order.line').write(cr, uid, [line.id], {'procurement_id': proc_id}) | 797 | self.pool.get('sale.order.line').write(cr, uid, [line.id], {'procurement_id': proc_id}) |
205 | 730 | if order.state == 'shipping_except': | 798 | if order.state == 'shipping_except': |
206 | @@ -739,11 +807,12 @@ | |||
207 | 739 | 807 | ||
208 | 740 | val = {} | 808 | val = {} |
209 | 741 | 809 | ||
211 | 742 | if picking_id: | 810 | if self._hook_ship_create_execute_picking_workflow(cr, uid, ids, context=context, picking_id=picking_id,): |
212 | 743 | wf_service.trg_validate(uid, 'stock.picking', picking_id, 'button_confirm', cr) | 811 | wf_service.trg_validate(uid, 'stock.picking', picking_id, 'button_confirm', cr) |
213 | 744 | 812 | ||
214 | 745 | for proc_id in proc_ids: | 813 | for proc_id in proc_ids: |
215 | 746 | wf_service.trg_validate(uid, 'procurement.order', proc_id, 'button_confirm', cr) | 814 | wf_service.trg_validate(uid, 'procurement.order', proc_id, 'button_confirm', cr) |
216 | 815 | self._hook_ship_create_execute_specific_code_01(cr, uid, ids, context=context, order=order, proc_id=proc_id,) | ||
217 | 747 | 816 | ||
218 | 748 | if order.state == 'shipping_except': | 817 | if order.state == 'shipping_except': |
219 | 749 | val['state'] = 'progress' | 818 | val['state'] = 'progress' |