434
434
(_check_po_from_fo, 'You cannot choose an internal supplier for this purchase order', []),
437
def _check_service(self, cr, uid, ids, vals, context=None):
439
Avoid the saving of a PO with non service products on Service PO
441
# UTP-871 : Remove check of service
444
if isinstance(ids, (int, long)):
448
if context.get('import_in_progress'):
451
for order in self.browse(cr, uid, ids, context=context):
452
for line in order.order_line:
453
if vals.get('categ', order.categ) == 'transport' and line.product_id and (line.product_id.type not in ('service', 'service_recep') or not line.product_id.transport_ok):
454
raise osv.except_osv(_('Error'), _('The product [%s]%s is not a \'Transport\' product. You can purchase only \'Transport\' products on a \'Transport\' purchase order. Please remove this line.') % (line.product_id.default_code, line.product_id.name))
456
elif vals.get('categ', order.categ) == 'service' and line.product_id and line.product_id.type not in ('service', 'service_recep'):
457
raise osv.except_osv(_('Error'), _('The product [%s] %s is not a \'Service\' product. You can purchase only \'Service\' products on a \'Service\' purchase order. Please remove this line.') % (line.product_id.default_code, line.product_id.name))
437
462
def purchase_cancel(self, cr, uid, ids, context=None):
439
464
Call the wizard to ask if you want to re-source the line
550
575
if 'partner_id' in vals:
551
576
self._check_user_company(cr, uid, vals['partner_id'], context=context)
578
self._check_service(cr, uid, ids, vals, context=context)
553
580
for order in self.browse(cr, uid, ids, context=context):
554
581
partner_type = self.pool.get('res.partner').browse(cr, uid, vals.get('partner_id', order.partner_id.id), context=context).partner_type
555
582
if vals.get('order_type'):
2147
2174
vals = self._get_location_id(cr, uid, vals, warehouse_id=vals.get('warehouse_id', False), context=context)
2149
2176
res = super(purchase_order, self).create(cr, uid, vals, context=context)
2177
self._check_service(cr, uid, [res], vals, context=context)
3567
3595
elif not product and not comment and not nomen_manda_0:
3568
3596
res['value'].update({'price_unit': 0.00, 'product_qty': 0.00, 'product_uom': False, 'old_price_unit': 0.00})
3570
3599
if context and context.get('categ') and product:
3571
3600
# Check consistency of product
3572
consistency_message = product_obj.check_consistency(cr, uid, product, context.get('categ'), context=context)
3601
consistency_message = self.pool.get('product.product').check_consistency(cr, uid, product, context.get('categ'), context=context)
3573
3602
if consistency_message:
3574
3603
res.setdefault('warning', {})
3575
3604
res['warning'].setdefault('title', 'Warning')
3785
3814
def check_consistency(self, cr, uid, product_id, category, context=None):
3787
3816
Check the consistency of product according to category
3788
:param cr: Cursor to the database
3789
:param uid: ID of the res.users that calls this method
3790
:param product_id: ID of the product.product to check
3791
:param category: DB value of the category to check
3792
:param context: Context of the call
3793
:return: A warning message or False
3795
nomen_obj = self.pool.get('product.nomenclature')
3818
context = context is None and {} or context
3800
3819
display_message = False
3802
3821
# No check for Other
3803
3822
if category == 'other':
3806
product = self.read(cr, uid, product_id, [
3825
product = self.read(cr, uid, product_id, ['nomen_manda_0', 'type', 'transport_ok'], context=context)
3811
3826
transport_product = product['transport_ok']
3812
3827
product_type = product['type']
3813
3828
main_type = product['nomen_manda_0'][0]
3815
3830
if category == 'medical':
3817
med_nomen = nomen_obj.search(cr, uid, [
3819
('name', '=', 'MED'),
3820
], context=context)[0]
3832
med_nomen = self.pool.get('product.nomenclature').search(cr,
3833
uid, [('level', '=', 0), ('name', '=', 'MED')],
3821
3835
except IndexError:
3822
raise osv.except_osv(
3824
_('MED nomenclature Main Type not found'),
3836
raise osv.except_osv(_('Error'), _('MED nomenclature Main Type not found'))
3827
3838
if main_type != med_nomen:
3828
3839
display_message = True
3830
3841
if category == 'log':
3832
log_nomen = nomen_obj.search(cr, uid, [
3834
('name', '=', 'LOG'),
3835
], context=context)[0]
3843
log_nomen = self.pool.get('product.nomenclature').search(cr,
3844
uid, [('level', '=', 0), ('name', '=', 'LOG')],
3837
3846
except IndexError:
3838
raise osv.except_osv(
3840
_('LOG nomenclature Main Type not found')
3847
raise osv.except_osv(_('Error'), _('LOG nomenclature Main Type not found'))
3843
3849
if main_type != log_nomen:
3844
3850
display_message = True