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

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