Merge lp:~unifield-team/unifield-addons/tender_refactoring into lp:unifield-addons

Proposed by Patrick Amstutz
Status: Merged
Merged at revision: 4487
Proposed branch: lp:~unifield-team/unifield-addons/tender_refactoring
Merge into: lp:unifield-addons
Diff against target: 147 lines (+77/-16)
2 files modified
procurement/procurement.py (+20/-2)
purchase/purchase.py (+57/-14)
To merge this branch: bzr merge lp:~unifield-team/unifield-addons/tender_refactoring
Reviewer Review Type Date Requested Status
UniField Dev Team Pending
Review via email: mp+75131@code.launchpad.net

Description of the change

Tender related

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 'procurement/procurement.py'
2--- procurement/procurement.py 2011-07-06 07:56:08 +0000
3+++ procurement/procurement.py 2011-09-13 09:05:24 +0000
4@@ -273,6 +273,24 @@
5 if not res:
6 return False
7 return res
8+
9+ def _partner_check_hook(self, cr, uid, ids, context=None, *args, **kwargs):
10+ '''
11+ check the if supplier is available or not
12+
13+ return the list of available partners
14+ '''
15+ procurement = kwargs['procurement']
16+ result = procurement.product_id.seller_ids
17+ return result
18+
19+ def _partner_get_hook(self, cr, uid, ids, context=None, *args, **kwargs):
20+ '''
21+ returns the partner from suppinfo
22+ '''
23+ procurement = kwargs['procurement']
24+ partner = procurement.product_id.seller_id #Taken Main Supplier of Product of Procurement.
25+ return partner
26
27 def check_buy(self, cr, uid, ids):
28 """ Checks product type.
29@@ -283,11 +301,11 @@
30 for procurement in self.browse(cr, uid, ids):
31 if procurement.product_id.product_tmpl_id.supply_method <> 'buy':
32 return False
33- if not procurement.product_id.seller_ids:
34+ if not self._partner_check_hook(cr, uid, ids, context=None, procurement=procurement):
35 cr.execute('update procurement_order set message=%s where id=%s',
36 (_('No supplier defined for this product !'), procurement.id))
37 return False
38- partner = procurement.product_id.seller_id #Taken Main Supplier of Product of Procurement.
39+ partner = self._partner_get_hook(cr, uid, ids, context=None, procurement=procurement)
40
41 if not partner:
42 cr.execute('update procurement_order set message=%s where id=%s',
43
44=== modified file 'purchase/purchase.py'
45--- purchase/purchase.py 2011-07-07 10:50:50 +0000
46+++ purchase/purchase.py 2011-09-13 09:05:24 +0000
47@@ -758,6 +758,40 @@
48 res = self.make_po(cr, uid, ids, context=context)
49 res = res.values()
50 return len(res) and res[0] or 0 #TO CHECK: why workflow is generated error if return not integer value
51+
52+ def get_partner_hook(self, cr, uid, ids, context=None, *args, **kwargs):
53+ '''
54+ return a dictionary with partner, seller_qty and seller_delay
55+ '''
56+ result = {}
57+
58+ procurement = kwargs['procurement']
59+ partner = procurement.product_id.seller_id # Taken Main Supplier of Product of Procurement.
60+ seller_qty = procurement.product_id.seller_qty
61+ seller_delay = int(procurement.product_id.seller_delay)
62+
63+ result.update(partner=partner,
64+ seller_qty=seller_qty,
65+ seller_delay=seller_delay)
66+
67+ return result
68+
69+ def po_values_hook(self, cr, uid, ids, context=None, *args, **kwargs):
70+ '''
71+ data for the purchase order creation
72+ '''
73+ values = kwargs['values']
74+ return values
75+
76+ def create_po_hook(self, cr, uid, ids, context=None, *args, **kwargs):
77+ '''
78+ creation of purchase order
79+ return the id of newly created po
80+ '''
81+ po_obj = self.pool.get('purchase.order')
82+ values = kwargs['values']
83+ purchase_id = po_obj.create(cr, uid, values, context=context)
84+ return purchase_id
85
86 def make_po(self, cr, uid, ids, context=None):
87 """ Make purchase order from procurement
88@@ -775,9 +809,12 @@
89 po_obj = self.pool.get('purchase.order')
90 for procurement in self.browse(cr, uid, ids, context=context):
91 res_id = procurement.move_id.id
92- partner = procurement.product_id.seller_id # Taken Main Supplier of Product of Procurement.
93- seller_qty = procurement.product_id.seller_qty
94- seller_delay = int(procurement.product_id.seller_delay)
95+
96+ # partner, seller_qty and seller_delay are computed with hook
97+ hook = self.get_partner_hook(cr, uid, ids, context=context, procurement=procurement)
98+ partner = hook['partner']
99+ seller_qty = hook['seller_qty']
100+ seller_delay = hook['seller_delay']
101 partner_id = partner.id
102 address_id = partner_obj.address_get(cr, uid, [partner_id], ['delivery'])['delivery']
103 pricelist_id = partner.property_product_pricelist_purchase.id
104@@ -789,9 +826,11 @@
105 qty = max(qty,seller_qty)
106
107 price = pricelist_obj.price_get(cr, uid, [pricelist_id], procurement.product_id.id, qty, partner_id, {'uom': uom_id})[pricelist_id]
108+ if hook.get('price_unit', False):
109+ price = hook.get('price_unit', False)
110
111 newdate = datetime.strptime(procurement.date_planned, '%Y-%m-%d %H:%M:%S')
112- newdate = (newdate - relativedelta(days=company.po_lead)) - relativedelta(days=seller_delay)
113+ newdate = (newdate - relativedelta(days=int(company.po_lead))) - relativedelta(days=int(seller_delay))
114
115 #Passing partner_id to context for purchase order line integrity of Line name
116 context.update({'lang': partner.lang, 'partner_id': partner_id})
117@@ -814,16 +853,20 @@
118 line.update({
119 'taxes_id': [(6,0,taxes)]
120 })
121- purchase_id = po_obj.create(cr, uid, {
122- 'origin': procurement.origin,
123- 'partner_id': partner_id,
124- 'partner_address_id': address_id,
125- 'location_id': procurement.location_id.id,
126- 'pricelist_id': pricelist_id,
127- 'order_line': [(0,0,line)],
128- 'company_id': procurement.company_id.id,
129- 'fiscal_position': partner.property_account_position and partner.property_account_position.id or False
130- })
131+ values = {
132+ 'origin': procurement.origin,
133+ 'partner_id': partner_id,
134+ 'partner_address_id': address_id,
135+ 'location_id': procurement.location_id.id,
136+ 'pricelist_id': pricelist_id,
137+ 'order_line': [(0,0,line)],
138+ 'company_id': procurement.company_id.id,
139+ 'fiscal_position': partner.property_account_position and partner.property_account_position.id or False,
140+ }
141+ # values modification from hook
142+ values = self.po_values_hook(cr, uid, ids, context=context, values=values, procurement=procurement)
143+ # purchase creation from hook
144+ purchase_id = self.create_po_hook(cr, uid, ids, context=context, values=values, procurement=procurement)
145 res[procurement.id] = purchase_id
146 self.write(cr, uid, [procurement.id], {'state': 'running', 'purchase_id': purchase_id})
147 return res

Subscribers

People subscribed via source and target branches

to all changes: