75
75
field_ids = field_obj.search(cr, uid, [('model', '=', self._name), ('name', '=', field)])
79
79
return field_obj.browse(cr, uid, field_ids[0]).field_description
81
81
def check_date_order(self, cr, uid, date=False, context=None):
83
83
Checks if the creation date of the order is in an opened period
85
85
@param : date : Creation date
86
86
@return True if the date is in an opened period, False if not
90
90
if context is None:
95
95
if isinstance(date, datetime):
96
96
date = date.strftime('%Y-%m-%d')
100
100
period_obj = self.pool.get('account.period')
101
## TODO: See if the period state changed in financial part of Unifiedl
101
# # TODO: See if the period state changed in financial part of Unifiedl
102
102
period_ids = period_obj.search(cr, uid, [('state', '=', 'draft')], context=context)
103
103
for p in period_obj.browse(cr, uid, period_ids, context=context):
104
104
if date >= p.date_start and date <= p.date_stop:
109
109
def check_delivery_requested(self, date=False, context=None):
111
111
Checks if the delivery requested date is equal of a date between today and today + 24 months
113
113
@param: Date to test (Delivery requested date)
114
114
@return : False if the date is not in the scale
118
118
if context is None:
125
125
if isinstance(date, datetime):
126
126
date = date.strftime('%Y-%m-%d')
129
129
two_years = (datetime.now() + relativedelta(years=2)).strftime('%Y-%m-%d')
130
130
if date >= (datetime.now()).strftime('%Y-%m-%d') and date <= two_years:
135
135
def check_delivery_confirmed(self, confirmed_date=False, date_order=False, context=None):
137
137
Checks if the delivery confirmed date is older than the creation date
139
139
@param: Date to test (Delivery requested date)
140
140
@return : False if the date is not in the scale
144
144
if context is None:
151
151
if isinstance(confirmed_date, datetime):
152
152
confirmed_date = confirmed_date.strftime('%Y-%m-%d')
154
154
if isinstance(date_order, datetime):
155
155
date_order = date_order.strftime('%Y-%m-%d')
158
158
if confirmed_date > date_order:
163
163
def check_dates(self, cr, uid, data, context=None):
165
165
Runs all tests on dates
169
169
if context is None:
171
171
# Comment this line if you would check date on PO/SO creation/write
174
174
date_order = data.get('date_order', False)
175
175
requested_date = data.get('delivery_requested_date', False)
176
176
confirmed_date = data.get('delivery_confirmed_date', False)
184
184
raise osv.except_osv(_('Error'), _('The Delivery Confirmed Date should be older than the Creation date !'))
185
185
if not check_delivery_confirmed(self, ready_to_ship, date_order, context=context):
186
186
raise osv.except_osv(_('Error'), _('The Ready to Ship Date should be older than the Creation date !'))
190
190
def common_internal_type_change(self, cr, uid, ids, internal_type, rts, shipment_date, context=None):
192
192
Common function when type of order is changing
196
196
if context is None:
337
337
# if < supplier_lt, display warning
338
338
if delta.days < partner.supplier_lt:
339
339
res.setdefault('warning', {}).update({'title': _('Warning'),
340
'message': _('The number of days between Creation Date and Delivery Expected Date (%s) is less than the supplier lead-time (%s).')%(delta.days,partner.supplier_lt,)})
340
'message': _('The number of days between Creation Date and Delivery Expected Date (%s) is less than the supplier lead-time (%s).') % (delta.days, partner.supplier_lt,)})
344
344
def common_onchange_transport_lt(self, cr, uid, ids, requested_date=False, transport_lt=0, type=False, res=None, context=None):
371
371
# if part, we get a dictionary from get_transport_lead_time
373
373
lead_time = lead_time.get(part)
374
res.setdefault('value', {}).update({'est_transport_lead_time': lead_time,})
374
res.setdefault('value', {}).update({'est_transport_lead_time': lead_time, })
375
375
# call onchange_transport_lt and update **VALUE** of res
376
376
res_transport_lt = self.onchange_transport_lt(cr, uid, ids, requested_date=requested_date, transport_lt=res['value']['est_transport_lead_time'], context=None)
377
377
res.setdefault('value', {}).update(res_transport_lt.setdefault('value', {}))
394
394
# call onchange_requested_date and update **VALUE** of res
395
395
res_requested_date = self.onchange_requested_date(cr, uid, ids, part=part, date_order=date_order, requested_date=res['value']['delivery_requested_date'], transport_lt=transport_lt, context=context)
396
396
res.setdefault('value', {}).update(res_requested_date.setdefault('value', {}))
400
400
def common_onchange_partner_id(self, cr, uid, ids, part=False, order_type=False, date_order=False, transport_lt=0, type=False, res=None, context=None):
413
413
res.setdefault('value', {}).update(res_requested_date.setdefault('value', {}))
414
414
# compute transport type
415
415
transport_type = compute_transport_type(self, cr, uid, part=part, type=type, context=context)
416
res.setdefault('value', {}).update({'transport_type': transport_type,})
416
res.setdefault('value', {}).update({'transport_type': transport_type, })
417
417
# call onchange_transport_type and update **VALUE** of res
418
418
res_transport_type = self.onchange_transport_type(cr, uid, ids, part=part, transport_type=res['value']['transport_type'], requested_date=res['value']['delivery_requested_date'], context=context)
419
419
res.setdefault('value', {}).update(res_transport_type.setdefault('value', {}))
420
420
# reset confirmed date
421
res.setdefault('value', {}).update({'delivery_confirmed_date': False,})
421
res.setdefault('value', {}).update({'delivery_confirmed_date': False, })
422
422
# compute partner type
423
423
partner_type = compute_partner_type(self, cr, uid, part=part, type=type, context=context)
424
res.setdefault('value', {}).update({'partner_type': partner_type,})
424
res.setdefault('value', {}).update({'partner_type': partner_type, })
426
426
internal_type = compute_internal_type(self, cr, uid, part=part, type=type, context=context)
427
res.setdefault('value', {}).update({'internal_type': internal_type,})
427
res.setdefault('value', {}).update({'internal_type': internal_type, })
431
431
def common_dates_change_on_line(self, cr, uid, ids, requested_date, confirmed_date, parent_class, context=None):
433
433
Checks if dates are later than header dates
437
437
if context is None:
439
439
min_confirmed = min_requested = False
441
441
order_id = context.get('active_id', [])
442
442
if isinstance(order_id, (int, long)):
443
443
order_id = [order_id]
446
446
min_confirmed = self.pool.get(parent_class).browse(cr, uid, order_id[0]).delivery_confirmed_date
447
447
min_requested = self.pool.get(parent_class).browse(cr, uid, order_id[0]).delivery_requested_date
449
449
for line in self.browse(cr, uid, ids, context=context):
450
450
min_confirmed = line.order_id.delivery_confirmed_date
451
451
min_requested = line.order_id.delivery_requested_date
453
return {'value': {'date_planned': requested_date,}}
453
return {'value': {'date_planned': requested_date, }}
454
454
# 'confirmed_delivery_date': confirmed_date}}
456
456
def common_create(self, cr, uid, data, type, context=None):
464
464
if data.get('partner_id', False):
465
465
partner = self.pool.get('res.partner').browse(cr, uid, data.get('partner_id'), context=context)
466
466
# partner type - always set
467
data.update({'partner_type': partner.partner_type,})
467
data.update({'partner_type': partner.partner_type, })
468
468
# internal type (zone) - always set
469
data.update({'internal_type': partner.zone,})
469
data.update({'internal_type': partner.zone, })
470
470
# transport type - only if not present (can be modified by user to False)
471
471
if 'transport_type' not in data:
472
data.update({'transport_type': partner.transport_0,})
472
data.update({'transport_type': partner.transport_0, })
473
473
# est_transport_lead_time - only if not present (can be modified by user to False)
474
474
if 'est_transport_lead_time' not in data:
475
data.update({'est_transport_lead_time': partner.transport_0_lt,})
476
# by default delivery requested date is equal to today + supplier lead time - filled for compatibility because requested date is now mandatory
475
data.update({'est_transport_lead_time': partner.transport_0_lt, })
476
# by default delivery requested date is equal to today + supplier lead time - filled for compatibility because requested date is now mandatory
477
477
if not data.get('delivery_requested_date', False):
478
478
# PO - supplier lead time / SO - customer lead time
498
498
if isinstance(ids, (int, long)):
501
501
if not 'date_order' in data:
502
502
data.update({'date_order': self.browse(cr, uid, ids[0]).date_order})
504
504
# fill partner_type and zone
505
505
if data.get('partner_id', False):
506
506
partner = self.pool.get('res.partner').browse(cr, uid, data.get('partner_id'), context=context)
507
507
# partner type - always set
508
data.update({'partner_type': partner.partner_type,})
508
data.update({'partner_type': partner.partner_type, })
509
509
# internal type (zone) - always set
510
data.update({'internal_type': partner.zone,})
510
data.update({'internal_type': partner.zone, })
511
511
# erase delivery_confirmed_date if partner_type is internal or section and the date is not filled by synchro - considered updated by synchro by default
512
512
if partner.partner_type in ('internal', 'section') and not data.get('confirmed_date_by_synchro', True):
513
data.update({'delivery_confirmed_date': False,})
513
data.update({'delivery_confirmed_date': False, })
515
515
check_dates(self, cr, uid, data, context=context)
517
517
return super(purchase_order, self).write(cr, uid, ids, data, context=context)
519
519
def create(self, cr, uid, data, context=None):
521
521
Checks if dates are good before creation
523
523
Delivery Requested Date: creation date + supplier lead time from partner (supplier_lt)
525
525
if context is None:
531
531
partner = self.pool.get('res.partner').browse(cr, uid, data.get('partner_id'), context=context)
532
532
# erase delivery_confirmed_date if partner_type is internal or section and the date is not filled by synchro - considered updated by synchro by default
533
533
if partner.partner_type in ('internal', 'section') and not data.get('confirmed_date_by_synchro', True):
534
data.update({'delivery_confirmed_date': False,})
534
data.update({'delivery_confirmed_date': False, })
536
536
check_dates(self, cr, uid, data, context=context)
538
538
return super(purchase_order, self).create(cr, uid, data, context=context)
540
540
def _get_receipt_date(self, cr, uid, ids, field_name, arg, context=None):
542
542
Returns the date of the first picking for the the PO
577
577
if obj.partner_id:
578
578
partner_type = obj.partner_id.partner_type
579
579
res[obj.id]['partner_type'] = partner_type
584
584
'delivery_requested_date': fields.date(string='Delivery Requested Date', required=True),
585
585
'delivery_confirmed_date': fields.date(string='Delivery Confirmed Date'),
586
586
'ready_to_ship_date': fields.date(string='Ready To Ship Date'),
587
587
'shipment_date': fields.date(string='Shipment Date', help='Date on which picking is created at supplier'),
588
588
'arrival_date': fields.date(string='Arrival date in the country', help='Date of the arrival of the goods at custom'),
589
'receipt_date': fields.function(_get_receipt_date, type='date', method=True, store=True,
589
'receipt_date': fields.function(_get_receipt_date, type='date', method=True, store=True,
590
590
string='Receipt Date', help='for a PO, date of the first godd receipt.'),
591
591
# BETA - to know if the delivery_confirmed_date can be erased - to be confirmed
592
592
'confirmed_date_by_synchro': fields.boolean(string='Confirmed Date by Synchro'),
595
595
'transport_type': fields.selection(selection=TRANSPORT_TYPE, string='Transport Mode',
596
596
help='Number of days this field has to be associated with a transport mode selection'),
597
597
# not a function because can be modified by user - **ONLY IN CREATE only if not in vals**
598
'est_transport_lead_time': fields.float(digits=(16,2), string='Est. Transport Lead Time',
598
'est_transport_lead_time': fields.float(digits=(16, 2), string='Est. Transport Lead Time',
599
599
help="Estimated Transport Lead-Time in weeks"),
600
600
# not a function because a function value is only filled when saved, not with on change of partner id
601
601
# from partner_id object
604
604
# from partner_id object
605
605
'internal_type': fields.selection(string='Type', selection=ZONE_SELECTION, readonly=True,),
609
609
'date_order': lambda *a: time.strftime('%Y-%m-%d'),
610
610
'confirmed_date_by_synchro': False,
613
613
def copy(self, cr, uid, id, default=None, context=None):
614
614
new_id = super(purchase_order, self).copy(cr, uid, id, default, context)
640
640
def internal_type_change(self, cr, uid, ids, internal_type, rts, shipment_date, context=None):
642
642
Set the shipment date if the internal_type == international
646
646
if context is None:
649
649
return {'value': common_internal_type_change(self, cr, uid, ids, internal_type, rts, shipment_date, context=context)}
651
651
def ready_to_ship_change(self, cr, uid, ids, ready_to_ship, date_order, shipment, context=None):
653
653
Checks the entered value
657
657
if context is None:
660
660
return common_ready_to_ship_change(self, cr, uid, ids, ready_to_ship, date_order, shipment, context=context)
662
662
def onchange_requested_date(self, cr, uid, ids, part=False, date_order=False, requested_date=False, transport_lt=0, order_type=False, context=None):
664
664
Set the confirmed date with the requested date if the first is not fill
675
675
# compute ready to ship date
676
676
res = common_requested_date_change(self, cr, uid, ids, part=part, date_order=date_order, requested_date=requested_date, transport_lt=transport_lt, type=get_type(self), res=res, context=context)
679
679
def onchange_internal_type(self, cr, uid, ids, order_type, partner_id, categ, dest_partner_id=False, warehouse_id=False, delivery_requested_date=False):
681
681
Set the delivery_confirmed_date if order_type == 'purchase_list'
704
704
# compute ready to ship date
705
705
res = common_onchange_transport_lt(self, cr, uid, ids, requested_date=requested_date, transport_lt=transport_lt, type=get_type(self), res=res, context=context)
708
708
def onchange_date_order(self, cr, uid, ids, part=False, date_order=False, transport_lt=0, context=None):
710
710
date_order is changed (creation date)
715
715
# compute requested date
716
716
res = common_onchange_date_order(self, cr, uid, ids, part=part, date_order=date_order, transport_lt=transport_lt, type=get_type(self), res=res, context=context)
719
719
def onchange_transport_type(self, cr, uid, ids, part=False, transport_type=False, requested_date=False, context=None):
721
721
transport type changed
722
722
requested date is in the signature because it is needed for children on_change call
725
725
if context is None:
742
742
# compute requested date and transport type
743
743
res = common_onchange_partner_id(self, cr, uid, ids, part=part, date_order=date_order, transport_lt=transport_lt, type=get_type(self), res=res, context=context)
746
746
def requested_data(self, cr, uid, ids, context=None):
748
748
data for requested
750
750
if context is None:
752
return {'name': _('Do you want to update the Requested Date of all order lines ?'),}
752
return {'name': _('Do you want to update the Requested Date of all order lines ?'), }
754
754
def confirmed_data(self, cr, uid, ids, context=None):
756
756
data for confirmed
758
758
if context is None:
760
return {'name': _('Do you want to update the Confirmed Delivery Date of all order lines ?'),}
760
return {'name': _('Do you want to update the Confirmed Delivery Date of all order lines ?'), }
762
762
def update_date(self, cr, uid, ids, context=None):
764
764
open the update lines wizard
777
777
wiz_obj = self.pool.get('wizard')
778
778
# open the selected wizard
779
779
return wiz_obj.open_wizard(cr, uid, ids, name=name, model=model, context=context)
785
785
class purchase_order_line(osv.osv):
786
_name= 'purchase.order.line'
786
_name = 'purchase.order.line'
787
787
_inherit = 'purchase.order.line'
789
789
def _vals_get_order_date(self, cr, uid, ids, fields, arg, context=None):
791
791
get values for functions
816
816
result = self.pool.get('purchase.order.line').search(cr, uid, [('order_id', 'in', ids)], context=context)
819
819
def _get_planned_date(self, cr, uid, context=None):
821
821
Returns planned_date
823
823
SPRINT3 validated
825
825
if context is None:
827
order_obj= self.pool.get('purchase.order')
827
order_obj = self.pool.get('purchase.order')
828
828
res = (datetime.now() + relativedelta(days=+2)).strftime('%Y-%m-%d')
830
830
if context.get('purchase_id', False):
831
831
po = order_obj.browse(cr, uid, context.get('purchase_id'), context=context)
832
832
res = po.delivery_requested_date
836
836
def _get_confirmed_date(self, cr, uid, context=None):
838
838
Returns confirmed date
840
840
SPRINT3 validated
842
842
if context is None:
844
order_obj= self.pool.get('purchase.order')
845
#The PO counterpart created should get for all line a delivery confirmed date blank
844
order_obj = self.pool.get('purchase.order')
845
# The PO counterpart created should get for all line a delivery confirmed date blank
846
846
if context.get('is_a_counterpart') or context.get('purchase_id', False) and order_obj.browse(cr, uid, context.get('purchase_id'), context=context).is_a_counterpart:
848
848
res = (datetime.now() + relativedelta(days=+2)).strftime('%Y-%m-%d')
850
850
if context.get('purchase_id', False):
851
851
po = order_obj.browse(cr, uid, context.get('purchase_id'), context=context)
852
852
res = po.delivery_confirmed_date
856
856
def _get_default_state(self, cr, uid, context=None):
858
858
default value for state fields.related
860
860
why, beacause if we try to pass state in the context,
861
861
the context is simply reset without any values specified...
863
863
if context is None:
865
865
if context.get('purchase_id', False):
866
order_obj= self.pool.get('purchase.order')
866
order_obj = self.pool.get('purchase.order')
867
867
po = order_obj.browse(cr, uid, context.get('purchase_id'), context=context)
872
872
_columns = {'date_planned': fields.date(string='Delivery Requested Date', required=True, select=True,
873
873
help='Header level dates has to be populated by default with the possibility of manual updates'),
874
874
'confirmed_delivery_date': fields.date(string='Delivery Confirmed Date',
877
877
'po_state_stored': fields.related('order_id', 'state', type='selection', selection=PURCHASE_ORDER_STATE_SELECTION, string='Po State', readonly=True,),
878
878
'po_partner_type_stored': fields.related('order_id', 'partner_type', type='selection', selection=PARTNER_TYPE, string='Po Partner Type', readonly=True,),
881
881
_defaults = {'po_state_stored': _get_default_state,
882
882
'po_partner_type_stored': lambda obj, cr, uid, c: c and c.get('partner_type', False),
883
883
'date_planned': _get_planned_date,
884
884
'confirmed_delivery_date': _get_confirmed_date,
887
887
def copy_data(self, cr, uid, id, default=None, context=None):
898
898
if 'date_planned' not in default:
899
899
default['date_planned'] = (datetime.now() + relativedelta(days=+2)).strftime('%Y-%m-%d')
900
900
return super(purchase_order_line, self).copy_data(cr, uid, id, default=default, context=context)
902
902
def dates_change(self, cr, uid, ids, requested_date, confirmed_date, context=None):
904
904
Checks if dates are later than header dates
908
908
if context is None:
925
925
if isinstance(ids, (int, long)):
928
928
for order in self.browse(cr, uid, ids, context=context):
929
929
# Fill partner type
930
930
partner = self.pool.get('res.partner').browse(cr, uid, data.get('partner_id', order.partner_id.id), context=context)
931
931
# partner type - always set
932
data.update({'partner_type': partner.partner_type,})
932
data.update({'partner_type': partner.partner_type, })
934
934
if not 'date_order' in data:
935
935
data.update({'date_order': self.browse(cr, uid, ids[0]).date_order})
937
937
check_dates(self, cr, uid, data, context=context)
939
939
return super(sale_order, self).write(cr, uid, ids, data, context=context)
941
941
def create(self, cr, uid, data, context=None):
943
943
Checks if dates are good before creation
950
950
# ready_to_ship_date only mandatory for so
951
951
if 'ready_to_ship_date' not in data:
952
952
rts = compute_rts(self, cr, uid, data.get('delivery_requested_date'), data.get('est_transport_lead_time'), type=get_type(self), context=context)
953
data.update({'ready_to_ship_date': rts,})
953
data.update({'ready_to_ship_date': rts, })
955
955
check_dates(self, cr, uid, data, context=context)
957
957
return super(sale_order, self).create(cr, uid, data, context=context)
959
959
def copy_data(self, cr, uid, id, default=None, context=None):
986
986
pick_obj = self.pool.get('stock.picking')
988
988
for order in self.browse(cr, uid, ids, context=context):
989
989
pick_ids = pick_obj.search(cr, uid, [('sale_id', '=', order.id)], offset=0, limit=1, order='date_done', context=context)
991
991
res[order.id] = False
993
993
res[order.id] = pick_obj.browse(cr, uid, pick_ids[0]).date_done
998
998
'date_order':fields.date(string='Creation Date', required=True, select=True, readonly=True, help="Date on which this document has been created.", states={'draft': [('readonly', False)]}),
999
999
'delivery_requested_date': fields.date(string='Delivery Requested Date', required=True),
1001
1001
'ready_to_ship_date': fields.date(string='Ready To Ship Date', required=True),
1002
1002
'shipment_date': fields.date(string='Shipment Date', readonly=True, help='Date on which picking is created at supplier'),
1003
1003
'arrival_date': fields.date(string='Arrival date in the country', help='Date of the arrival of the goods at custom'),
1004
'receipt_date': fields.function(_get_receipt_date, type='date', method=True, store=True,
1004
'receipt_date': fields.function(_get_receipt_date, type='date', method=True, store=True,
1005
1005
string='Receipt Date', help='for a PO, date of the first godd receipt.'),
1006
1006
# BETA - to know if the delivery_confirmed_date can be erased - to be confirmed
1007
1007
'confirmed_date_by_synchro': fields.boolean(string='Confirmed Date by Synchro'),
1010
1010
'transport_type': fields.selection(selection=TRANSPORT_TYPE, string='Transport Mode',
1011
1011
help='Number of days this field has to be associated with a transport mode selection'),
1012
1012
# not a function because can be modified by user - **ONLY IN CREATE only if not in vals**
1013
'est_transport_lead_time': fields.float(digits=(16,2), string='Est. Transport Lead Time', help="Estimated Transport Lead-Time in weeks"),
1013
'est_transport_lead_time': fields.float(digits=(16, 2), string='Est. Transport Lead Time', help="Estimated Transport Lead-Time in weeks"),
1014
1014
# not a function because a function value is only filled when saved, not with on change of partner id
1015
1015
# from partner_id object
1016
1016
'partner_type': fields.selection(string='Partner Type', selection=PARTNER_TYPE, readonly=True,),
1018
1018
# from partner_id object
1019
1019
'internal_type': fields.selection(string='Type', selection=ZONE_SELECTION, readonly=True,),
1023
1023
'date_order': lambda *a: time.strftime('%Y-%m-%d'),
1024
1024
'confirmed_date_by_synchro': False,
1027
1027
def internal_type_change(self, cr, uid, ids, internal_type, rts, shipment_date, context=None):
1029
1029
Set the shipment date if the internal_type == international
1033
1033
if context is None:
1036
1036
return {'value': common_internal_type_change(self, cr, uid, ids, internal_type, rts, shipment_date, context=context)}
1038
1038
def ready_to_ship_change(self, cr, uid, ids, ready_to_ship, date_order, shipment, context=None):
1040
1040
Checks the entered value
1044
1044
if context is None:
1047
1047
return common_ready_to_ship_change(self, cr, uid, ids, ready_to_ship, date_order, shipment, context=context)
1049
1049
def onchange_requested_date(self, cr, uid, ids, part=False, date_order=False, requested_date=False, transport_lt=0, context=None):
1051
1051
Set the confirmed date with the requested date if the first is not fill
1069
1069
# compute ready to ship date
1070
1070
res = common_onchange_transport_lt(self, cr, uid, ids, requested_date=requested_date, transport_lt=transport_lt, type=get_type(self), res=res, context=context)
1073
1073
def onchange_transport_type(self, cr, uid, ids, part=False, transport_type=False, requested_date=False, context=None):
1075
1075
transport type changed
1076
1076
requested date is in the signature because it is needed for children on_change call
1078
1078
SPRINT3 validated - YAML ok
1080
1080
if context is None:
1083
1083
res = common_onchange_transport_type(self, cr, uid, ids, part=part, transport_type=transport_type, requested_date=requested_date, type=get_type(self), res=res, context=context)
1086
1086
def onchange_partner_id(self, cr, uid, ids, part=False, order_type=False, date_order=False, transport_lt=0, context=None):
1088
1088
Fills the Requested and Confirmed delivery dates
1090
1090
SPRINT3 validated - YAML ok
1092
1092
if isinstance(ids, (int, long)):
1096
1096
res = super(sale_order, self).onchange_partner_id(cr, uid, ids, part, order_type)
1097
1097
# compute requested date and transport type
1098
1098
res = common_onchange_partner_id(self, cr, uid, ids, part=part, order_type=order_type, date_order=date_order, transport_lt=transport_lt, type=get_type(self), res=res, context=context)
1100
1100
if res.get('value', {}).get('pricelist_id') and part:
1102
1102
if isinstance(ids, (int, long)):
1105
1105
order = self.pool.get('sale.order').browse(cr, uid, ids[0])
1106
1106
partner = self.pool.get('res.partner').browse(cr, uid, part)
1107
1107
pricelist_ids = self.pool.get('product.pricelist').search(cr, uid, [('type', '=', 'sale'), ('in_search', '=', partner.partner_type)])
1123
1123
# compute requested date
1124
1124
res = common_onchange_date_order(self, cr, uid, ids, part=part, date_order=date_order, transport_lt=transport_lt, type=get_type(self), res=res, context=context)
1127
1127
def requested_data(self, cr, uid, ids, context=None):
1129
1129
data for requested for change line wizard
1131
1131
if context is None:
1133
return {'name': _('Do you want to update the Requested Date of all order lines ?'),}
1133
return {'name': _('Do you want to update the Requested Date of all order lines ?'), }
1135
1135
def confirmed_data(self, cr, uid, ids, context=None):
1137
1137
data for confirmed for change line wizard
1139
1139
if context is None:
1141
return {'name': _('Do you want to update the Confirmed Delivery Date of all order lines ?'),}
1141
return {'name': _('Do you want to update the Confirmed Delivery Date of all order lines ?'), }
1143
1143
def update_date(self, cr, uid, ids, context=None):
1145
1145
open the update lines wizard
1158
1158
wiz_obj = self.pool.get('wizard')
1159
1159
# open the selected wizard
1160
1160
return wiz_obj.open_wizard(cr, uid, ids, name=name, model=model, context=context)
1162
def _hook_ship_create_stock_move(self, cr, uid, ids, context=None, *args, **kwargs):
1164
Please copy this to your module's method also.
1165
This hook belongs to the action_ship_create method from sale>sale.py
1167
- allow to modify the data for stock move creation
1172
date_tools = self.pool.get('date.tools')
1173
fields_tools = self.pool.get('fields.tools')
1174
db_date_format = date_tools.get_db_date_format(cr, uid, context=context)
1176
move_data = super(sale_order, self)._hook_ship_create_stock_move(cr, uid, ids, context=context, *args, **kwargs)
1177
order = kwargs['order']
1178
# get shipment lead time
1179
shipment_lt = fields_tools.get_field_from_company(cr, uid, object=self._name, field='shipment_lead_time', context=context)
1180
# date = rts of so - by default, a picking is created
1181
rts = order.ready_to_ship_date
1182
# date, date_expected
1183
move_data.update({'date': rts,'date_expected': rts})
1187
def _hook_ship_create_procurement_order(self, cr, uid, ids, context=None, *args, **kwargs):
1189
Please copy this to your module's method also.
1190
This hook belongs to the action_ship_create method from sale>sale.py
1192
- allow to modify the data for procurement order creation
1197
date_tools = self.pool.get('date.tools')
1198
fields_tools = self.pool.get('fields.tools')
1199
db_date_format = date_tools.get_db_date_format(cr, uid, context=context)
1201
result = super(sale_order, self)._hook_ship_create_procurement_order(cr, uid, ids, context=context, *args, **kwargs)
1202
# date_planned = rts - company.prep_lt
1203
order = kwargs['order']
1204
# get value from company
1205
prep_lt = fields_tools.get_field_from_company(cr, uid, object=self._name, field='preparation_lead_time', context=context)
1207
rts = datetime.strptime(order.ready_to_ship_date, db_date_format)
1208
rts = rts - relativedelta(days=prep_lt or 0)
1209
rts = rts.strftime(db_date_format)
1210
result['date_planned'] = rts
1211
# update from yml flag
1212
result['from_yml_test'] = order.from_yml_test
1219
1165
class sale_order_line(osv.osv):
1220
_name= 'sale.order.line'
1166
_name = 'sale.order.line'
1221
1167
_inherit = 'sale.order.line'
1223
1169
def _get_planned_date(self, cr, uid, context=None):
1225
1171
Returns planned_date
1227
1173
if context is None:
1229
order_obj= self.pool.get('sale.order')
1175
order_obj = self.pool.get('sale.order')
1230
1176
res = (datetime.now() + relativedelta(days=+2)).strftime('%Y-%m-%d')
1232
1178
if context.get('sale_id', False):
1233
1179
so = order_obj.browse(cr, uid, context.get('sale_id'), context=context)
1234
1180
res = so.delivery_requested_date
1238
1184
def _get_confirmed_date(self, cr, uid, context=None):
1242
1188
if context is None:
1244
order_obj= self.pool.get('sale.order')
1190
order_obj = self.pool.get('sale.order')
1245
1191
res = (datetime.now() + relativedelta(days=+2)).strftime('%Y-%m-%d')
1247
1193
if context.get('sale_id', False):
1248
1194
so = order_obj.browse(cr, uid, context.get('sale_id'), context=context)
1249
res = so.delivery_confirmed_date
1195
res = so.delivery_confirmed_date
1253
1199
def _get_default_state(self, cr, uid, context=None):
1255
1201
default value for state fields.related
1257
1203
why, beacause if we try to pass state in the context,
1258
1204
the context is simply reset without any values specified...
1260
1206
if context is None:
1262
1208
if context.get('sale_id', False):
1263
order_obj= self.pool.get('sale.order')
1209
order_obj = self.pool.get('sale.order')
1264
1210
so = order_obj.browse(cr, uid, context.get('sale_id'), context=context)
1265
1211
return so.state
1269
1215
def _get_uom_def(self, cr, uid, context=None):
1270
1216
if context is None:
1273
1219
ids = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'product', 'product_uom_unit')
1274
1220
except ValueError:
1306
1252
if 'date_planned' not in default:
1307
1253
default['date_planned'] = (datetime.now() + relativedelta(days=+2)).strftime('%Y-%m-%d')
1308
1254
return super(sale_order_line, self).copy_data(cr, uid, id, default=default, context=context)
1310
1256
def dates_change(self, cr, uid, ids, requested_date, confirmed_date, context=None):
1312
Checks if dates are later than header dates
1258
Checks if dates are later than header dates
1316
1262
if context is None:
1318
1264
return common_dates_change_on_line(self, cr, uid, ids, requested_date, confirmed_date, 'sale.order', context=context)
1320
1266
sale_order_line()
1339
1285
procurement = kwargs['procurement']
1340
1286
# date_planned (requested date) = date_planned from procurement order (rts - prepartion lead time)
1341
1287
# confirmed_delivery_date (confirmed date) = False
1342
line.update({'date_planned': procurement.date_planned, 'confirmed_delivery_date': False,})
1288
line.update({'date_planned': procurement.date_planned, 'confirmed_delivery_date': False, })
1345
1291
def po_values_hook(self, cr, uid, ids, context=None, *args, **kwargs):
1347
1293
Please copy this to your module's method also.
1348
1294
This hook belongs to the make_po method from purchase>purchase.py>procurement_order
1350
1296
- allow to modify the data for purchase order creation
1352
1298
if context is None:
1427
1373
'manual_min_date_stock_picking': fields.datetime(string='Manual Date'),
1428
1374
'min_date_manually': fields.boolean(string='change manually')
1431
1377
_defaults = {'manual_min_date_stock_picking': False,
1432
'min_date_manually': False,}
1378
'min_date_manually': False, }
1434
1380
def change_min_date(self, cr, uid, ids, context=None):
1435
1381
return {'value': {'min_date_manually': True}}
1437
1383
def create(self, cr, uid, vals, context=None):
1438
1384
if not vals.get('purchase id') or not vals.get('sale_id'):
1439
1385
vals['manual_min_date_stock_picking'] = vals.get('min_date')
1440
1386
return super(stock_picking, self).create(cr, uid, vals, context=context)
1442
1388
def write(self, cr, uid, ids, vals, context=None):
1444
1390
Update all stock moves if the min_date of the picking was changed manually
1449
1395
vals.update({'manual_min_date_stock_picking': vals.get('min_date', vals.get('manual_min_date_stock_picking'))})
1450
1396
move_ids = move_obj.search(cr, uid, [('picking_id', '=', pick.id), ('state', 'not in', ('done', 'cancel'))], context=context)
1451
1397
move_obj.write(cr, uid, move_ids, {'date_expected': vals.get('min_date', vals.get('manual_min_date_stock_picking'))}, context=context)
1453
1399
return super(stock_picking, self).write(cr, uid, ids, vals, context=context)
1455
1401
# @@@override stock>stock.py>stock_picking>do_partial
1472
1418
today = time.strftime(date_format)
1473
1419
today_db = time.strftime(db_date_format)
1474
1420
so_obj.write(cr, uid, [sale_id], {'shipment_date': today_db})
1475
so_obj.log(cr, uid, sale_id, _("Shipment Date of the Field Order '%s' has been updated to %s.")%(picking.sale_id.name, today))
1421
so_obj.log(cr, uid, sale_id, _("Shipment Date of the Field Order '%s' has been updated to %s.") % (picking.sale_id.name, today))
1478
1424
stock_picking()
1483
1429
shipment date of sale order is updated
1485
1431
_inherit = 'stock.move'
1487
1433
def default_get(self, cr, uid, fields, context=None):
1488
1434
if not context:
1491
1437
res = super(stock_move, self).default_get(cr, uid, fields, context=context)
1492
1438
res['date'] = res['date_expected'] = context.get('date_expected', time.strftime('%Y-%m-%d %H:%M:%S'))
1496
1442
def do_partial(self, cr, uid, ids, partial_datas, context=None):
1498
1444
update shipment date and logged
1512
1458
today = time.strftime(date_format)
1513
1459
today_db = time.strftime(db_date_format)
1514
1460
so_obj.write(cr, uid, [sale_id], {'shipment_date': today_db})
1515
so_obj.log(cr, uid, sale_id, _("Shipment Date of the Field Order '%s' has been updated to %s.")%(obj.picking_id.sale_id.name, today))
1461
so_obj.log(cr, uid, sale_id, _("Shipment Date of the Field Order '%s' has been updated to %s.") % (obj.picking_id.sale_id.name, today))
1523
1469
add time related fields
1525
1471
_inherit = 'res.company'
1527
_columns = {'shipment_lead_time': fields.float(digits=(16,2), string='Shipment Lead Time'),
1528
'preparation_lead_time': fields.float(digits=(16,2), string='Preparation Lead Time'),
1473
_columns = {'shipment_lead_time': fields.float(digits=(16, 2), string='Shipment Lead Time'),
1474
'preparation_lead_time': fields.float(digits=(16, 2), string='Preparation Lead Time'),
1531
1477
_defaults = {'shipment_lead_time': 0.0,
1532
1478
'preparation_lead_time': 0.0,
1533
'po_lead': lambda *a: 0.0, # removed from processes - set to 0.0 for security
1479
'po_lead': lambda *a: 0.0, # removed from processes - set to 0.0 for security