~unifield-team/unifield-wm/us-826

« back to all changes in this revision

Viewing changes to procurement_cycle/scheduler.py

  • Committer: jf
  • Date: 2014-03-14 09:48:25 UTC
  • mfrom: (1728.29.9 unifield-wm)
  • mto: This revision was merged to the branch mainline in revision 2032.
  • Revision ID: jfb@tempo-consulting.fr-20140314094825-himvju927nro52no
UTP-124 [IMP] Replenishmenty Rules Order Cycle and Theshold Computed Values Contain Data on Main Parameters
lp:~unifield-team/unifield-wm/utp-124

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
from datetime import datetime
24
24
from tools.translate import _
25
25
from mx.DateTime import RelativeDate
 
26
from mx.DateTime import RelativeDateTime
26
27
from mx.DateTime import now
27
28
from mx.DateTime import Parser
28
29
 
80
81
                for line in cycle.product_ids:
81
82
                    # Update the safety stock according to the safety stock defined in the line
82
83
                    d_values.update({'safety_stock': line.safety_stock})
83
 
                    proc_id = self.create_proc_cycle(cr, uid, cycle, line.product_id.id, location_id, d_values)
 
84
                    proc_id = self.create_proc_cycle(cr, uid, cycle, line.product_id.id, location_id, d_values, line)
84
85
 
85
86
                    if proc_id:
86
87
                        created_proc.append(proc_id)
132
133
            
133
134
        return {}
134
135
    
135
 
    def create_proc_cycle(self, cr, uid, cycle, product_id, location_id, d_values=None, context=None):
 
136
    def create_proc_cycle(self, cr, uid, cycle, product_id, location_id, d_values=None, line=None, context=None):
136
137
        '''
137
138
        Creates a procurement order for a product and a location
138
139
        '''
160
161
            context.update({'from_date': d_values.get('consumption_period_from'), 'to_date': d_values.get('consumption_period_to')})
161
162
        
162
163
        product = product_obj.browse(cr, uid, product_id[0], context=context)
163
 
            
164
 
        newdate = datetime.today()
 
164
 
 
165
        newdate = datetime.today().strftime('%Y-%m-%d %H:%M:%S')
 
166
        if line and line.required_date:
 
167
            newdate = line.required_date
 
168
 
165
169
        quantity_to_order = self._compute_quantity(cr, uid, cycle, product, location_id, d_values, context=context)
166
170
            
167
171
        # Create a procurement only if the quantity to order is more than 0.00
171
175
            proc_id = proc_obj.create(cr, uid, {
172
176
                                    'name': _('Procurement cycle: %s') % (cycle.name,),
173
177
                                    'origin': cycle.name,
174
 
                                    'date_planned': newdate.strftime('%Y-%m-%d %H:%M:%S'),
 
178
                                    'date_planned': newdate,
175
179
                                    'product_id': product.id,
176
180
                                    'product_qty': quantity_to_order,
177
181
                                    'product_uom': product.uom_id.id,
195
199
        '''
196
200
        if d_values is None:
197
201
            d_values = {}
198
 
        
 
202
 
199
203
        # Get the delivery lead time of the product if the leadtime is not defined in rule and no supplier found in product form
200
204
        delivery_leadtime = product.procure_delay and round(int(product.procure_delay)/30.0, 2) or 1
201
205
        # Get the leadtime of the rule if defined
223
227
        available_qty = self.get_available(cr, uid, product.id, location_id, monthly_consumption, d_values)
224
228
        
225
229
        qty_to_order = (delivery_leadtime * monthly_consumption) + (order_coverage * monthly_consumption) - available_qty
226
 
        
227
 
        return round(self.pool.get('product.uom')._compute_qty(cr, uid, product.uom_id.id, qty_to_order, product.uom_id.id), 2)
228
 
        
 
230
 
 
231
        if not context.get('get_data', False):
 
232
            res = round(self.pool.get('product.uom')._compute_qty(cr, uid, product.uom_id.id, qty_to_order, product.uom_id.id), 2)
 
233
        else:
 
234
            delta = 0
 
235
            if monthly_consumption:
 
236
                delta = available_qty / monthly_consumption * 30
 
237
 
 
238
            if delta <= 0.00:
 
239
                req_date = now().strftime('%Y-%m-%d')
 
240
            else:
 
241
                req_date = (now() + RelativeDateTime(days=delta)).strftime('%Y-%m-%d')
 
242
            res = round(self.pool.get('product.uom')._compute_qty(cr, uid, product.uom_id.id, qty_to_order, product.uom_id.id), 2), req_date
 
243
 
 
244
        return res
229
245
        
230
246
    def get_available(self, cr, uid, product_id, location_id, monthly_consumption, d_values=None, context=None):
231
247
        '''