Merge lp:~jfb-tempo-consulting/unifield-server/us-1765 into lp:unifield-server

Proposed by jftempo
Status: Merged
Merge reported by: jftempo
Merged at revision: not available
Proposed branch: lp:~jfb-tempo-consulting/unifield-server/us-1765
Merge into: lp:unifield-server
Diff against target: 57 lines (+21/-4)
1 file modified
bin/addons/purchase_override/purchase.py (+21/-4)
To merge this branch: bzr merge lp:~jfb-tempo-consulting/unifield-server/us-1765
Reviewer Review Type Date Requested Status
UniField Dev Team Pending
Review via email: mp+308039@code.launchpad.net
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 'bin/addons/purchase_override/purchase.py'
2--- bin/addons/purchase_override/purchase.py 2016-09-26 07:39:38 +0000
3+++ bin/addons/purchase_override/purchase.py 2016-10-10 12:23:14 +0000
4@@ -416,9 +416,12 @@
5 string='Update in progress',
6 readonly=True,
7 ),
8+ # US-1765: register the 1st call of wkf_confirm_trigger to prevent recursion error
9+ 'po_confirmed': fields.boolean('PO', readonly=True),
10 }
11
12 _defaults = {
13+ 'po_confirmed': lambda *a: False,
14 'order_type': lambda *a: 'regular',
15 'priority': lambda *a: 'normal',
16 'categ': lambda *a: 'other',
17@@ -1815,7 +1818,6 @@
18 context = {}
19 if isinstance(ids, (int, long)):
20 ids = [ids]
21-
22 # objects
23 so_obj = self.pool.get('sale.order')
24 wf_service = netsvc.LocalService("workflow")
25@@ -1829,14 +1831,29 @@
26 # from all so, list all corresponding po second level
27 all_po_for_all_so_ids = so_obj.get_po_ids_from_so_ids(cr, uid, all_so_ids, context=context)
28
29+ # we trigger all the corresponding sale order -> test_lines is called on these so
30+ for so_id in all_so_ids:
31+ wf_service.trg_write(uid, 'sale.order', so_id, cr)
32+
33 not_confirmed_po = self.search(cr, uid, [
34 ('id', 'not in', all_po_for_all_so_ids),
35 ('state', '=', 'confirmed_wait'),
36 ], context=context)
37
38- # we trigger all the corresponding sale order -> test_lines is called on these so
39- for so_id in all_so_ids:
40- wf_service.trg_write(uid, 'sale.order', so_id, cr)
41+ # US-1765: PO linked to multiple POs, last PO confirmed
42+ # wkf_confirm_trigger is called for this PO and after again and again and again for each linked POs (by the workflow)
43+ # register the first call by setting po_confirmed=True and do not process the others
44+ confirmed = False
45+ if all_po_for_all_so_ids:
46+ confirmed = self.search(cr, uid,
47+ [('id', 'in', all_po_for_all_so_ids), ('po_confirmed', '=', True)], context=context)
48+ if confirmed:
49+ # one of the linked PO has already triggered this method for all POs, so we can stop
50+ return True
51+ if ids:
52+ # register the call
53+ # direct sql to not trigger (again) the workflow
54+ cr.execute('''update purchase_order set po_confirmed='t' where id in %s''', (tuple(ids),))
55
56 # we trigger pos of all sale orders -> all_po_confirm is called on these po
57 for po_id in all_po_for_all_so_ids:

Subscribers

People subscribed via source and target branches