71
71
'requestor': fields.char(size=128, string='Requestor'),
72
'procurement_request': fields.boolean(string='Procurement Request', readonly=True),
72
'procurement_request': fields.boolean(string='Internal Request', readonly=True),
73
73
'requested_date': fields.date(string='Requested date'),
74
74
'warehouse_id': fields.many2one('stock.warehouse', string='Warehouse'),
75
75
'origin': fields.char(size=64, string='Origin'),
78
78
'request_id', 'order_id', string='Orders', readonly=True),
80
80
# Remove readonly parameter from sale.order class
81
'order_line': fields.one2many('sale.order.line', 'order_id', 'Order Lines', readonly=True, states={'procurement': [('readonly', False)], 'draft': [('readonly', False)]}),
81
'order_line': fields.one2many('sale.order.line', 'order_id', 'Order Lines', readonly=True, states={'draft': [('readonly', False)]}),
82
82
'amount_untaxed': fields.function(_amount_all, method=True, digits_compute= dp.get_precision('Sale Price'), string='Untaxed Amount',
84
84
'sale.order': (lambda self, cr, uid, ids, c={}: ids, ['order_line'], 10),
99
99
multi='sums', help="The total amount."),
100
100
'state': fields.selection([
101
('procurement', 'Internal Supply Requirement'),
102
('draft', 'Quotation'),
103
102
('waiting_date', 'Waiting Schedule'),
104
('manual', 'Manual In Progress'),
105
('progress', 'In Progress'),
103
('manual', 'Confirmed'),
104
('progress', 'Confirmed'),
105
('validated', 'Validated'),
106
106
('shipping_except', 'Shipping Exception'),
107
107
('invoice_except', 'Invoice Exception'),
109
109
('cancel', 'Cancelled')
110
110
], 'Order State', readonly=True, help="Gives the state of the quotation or sales order. \nThe exception state is automatically set when a cancel operation occurs in the invoice validation (Invoice Exception) or in the picking list process (Shipping Exception). \nThe 'Waiting Schedule' state is set when the invoice is confirmed but waiting for the scheduler to run on the date 'Ordered Date'.", select=True),
114
'name': lambda obj, cr, uid, context: not context.get('procurement_request', False) and obj.pool.get('ir.sequence').get(cr, uid, 'sale.order') or '',
114
'name': lambda obj, cr, uid, context: not context.get('procurement_request', False) and obj.pool.get('ir.sequence').get(cr, uid, 'sale.order') or obj.pool.get('ir.sequence').get(cr, uid, 'procurement.request'),
115
115
'procurement_request': lambda obj, cr, uid, context: context.get('procurement_request', False),
116
'state': lambda self, cr, uid, c: c.get('procurement_request', False) and 'procurement' or 'draft',
119
119
def create(self, cr, uid, vals, context={}):
123
if context.get('procurement_request'):
123
if context.get('procurement_request') or vals.get('procurement_request', False):
124
124
# Get the ISR number
125
125
if not vals.get('name', False):
126
126
vals.update({'name': self.pool.get('ir.sequence').get(cr, uid, 'procurement.request')})
152
152
for request in self.browse(cr, uid, ids, context=context):
153
if request.procurement_request and request.state in ['procurement', 'cancel']:
153
if request.procurement_request and request.state in ['draft', 'cancel']:
154
154
del_ids.append(request.id)
155
155
elif not request.procurement_request:
156
156
normal_ids.append(request.id)
158
raise osv.except_osv(_('Invalid action !'), _('Cannot delete Procurement Request(s) which are already confirmed !'))
158
raise osv.except_osv(_('Invalid action !'), _('Cannot delete Internal Request(s) which are already validated !'))
161
161
osv.osv.unlink(self, cr, uid, del_ids, context=context)
198
198
return super(osv.osv, self).copy(cr, uid, id, default, context=context)
200
def validate_procurement(self, cr, uid, ids, context={}):
204
self.write(cr, uid, ids, {'state': 'validated'}, context=context)
200
208
def confirm_procurement(self, cr, uid, ids, context={}):
202
210
Confirmed the request
204
self.write(cr, uid, ids, {'state': 'progress'})
212
self.write(cr, uid, ids, {'state': 'progress'}, context=context)
214
for request in self.browse(cr, uid, ids, context=context):
215
message = _("The internal request '%s' has been confirmed.") %(request.name,)
216
self.log(cr, uid, request.id, message)
253
265
return super(procurement_request_line, self).create(cr, uid, vals, context=context)
256
'procurement_request': fields.boolean(string='Procurement Request', readonly=True),
268
'procurement_request': fields.boolean(string='Internal Request', readonly=True),
257
269
'latest': fields.char(size=64, string='Latest documents', readonly=True),
258
270
'price_subtotal': fields.function(_amount_line, method=True, string='Subtotal', digits_compute= dp.get_precision('Sale Price')),
271
'my_company_id': fields.many2one('res.company','Company',select=1),
272
'supplier': fields.many2one('res.partner', 'Supplier', domain="[('id', '!=', my_company_id)]"),
261
275
def _get_planned_date(self, cr, uid, c={}):
270
284
'procurement_request': lambda self, cr, uid, c: c.get('procurement_request', False),
271
285
'date_planned': _get_planned_date,
286
'my_company_id': lambda obj, cr, uid, context: obj.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.id,
274
289
def requested_product_id_change(self, cr, uid, ids, product_id, type, context={}):