~sebastien.beau/+junk/advanced-project-management-61-purchase-refactor

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
=== modified file 'project_product_resource/project_product_resource.py'
--- project_product_resource/project_product_resource.py	2011-03-31 19:41:46 +0000
+++ project_product_resource/project_product_resource.py	2011-04-01 00:52:12 +0000
@@ -24,7 +24,7 @@
 from osv import fields, osv
 from datetime import datetime
 import netsvc
-
+from itertools import groupby
 
 class project_product_allocation(osv.osv):
     _name = 'project.product.allocation'
@@ -99,13 +99,24 @@
                     raise osv.except_osv(_('Data Insufficient !'), _('In order to plan the material expeditions, you should define source and target locations for this project'))
                 if phase.product_ids and not phase.date_start:
                     raise osv.except_osv(_('Data Insufficient !'), _('In order to plan the material requisitions, you need to define a start date for phase: %s!') % (phase.name,))
+
+
+
                 can_create_picking = True
                 for picking in phase.picking_ids:
                     if picking.state != "cancel":
                         can_create_picking = False #only create picking if none is there already.
                 if can_create_picking: 
                     proc_ids = []
-                    picking_id = self.pool.get('stock.picking').create(cr, uid, {
+
+                purchase
+                picking_groups = {}
+
+                def get_or_create_picking(kind):
+                     if picking_groups[kind]:
+                         return picking_groups[kind]
+                     else:
+                         picking_id = self.pool.get('stock.picking').create(cr, uid, {
                                     'name': phase.name,
                                     'origin': "project " + phase.project_id.name + " - " + phase.name,
                                     'type': 'out',
@@ -117,9 +128,13 @@
                                     'invoice_state': '2binvoiced',
                                     'company_id': phase.project_id.company_id.id,
                                     'phase_id': phase.id
-                                })
-                    res[phase.id] = picking_id
+                         })
+                         picking_groups[kind] = picking_id
+                         return picking_id
+
+
                     order = False
+
                     for project_product_allocation in phase.product_ids:
                         if project_product_allocation.sale_id:#TODO because of that condition picking might be empty, check before!
                             line = project_product_allocation.sale_id
@@ -127,7 +142,7 @@
                             date_planned = phase.date_start or datetime.now()
                             move_id = self.pool.get('stock.move').create(cr, uid, {
                                     'name': project_product_allocation.product_id.name,
-                                    'picking_id': picking_id,
+                                    'picking_id': get_or_create_picking(project_product_allocation.product_id.sale_flow),
                                     'product_id': project_product_allocation.product_id.id,
                                     'date_planned': date_planned,
                                     'date_expected': date_planned,
@@ -142,7 +157,7 @@
                                     'sale_line_id': line.id,
                                     #'tracking_id': False,
                                     'state': 'draft',
-                                    #'state': 'waiting',
+                                    'invoice_state': project_product_allocation.product_id.sale_flow in ('normal', 'direct_delivery') and '2binvoiced' or 'none',
                                     #'note': line.notes,
                                     'company_id': phase.project_id.company_id.id,
                                 })