[FIX] Product:delete a product category if it contained products previously
lp bug: https://launchpad.net/bugs/698023 fixed bzr revid: aag@tinyerp.co.in-20110113113735-ed412zqg9dc1ve0c
This commit is contained in:
parent
5a046d9510
commit
0fab39cc6d
|
@ -302,7 +302,17 @@ class product_template(osv.osv):
|
|||
'loc_case': fields.char('Case', size=16),
|
||||
'company_id': fields.many2one('res.company', 'Company',select=1),
|
||||
}
|
||||
|
||||
|
||||
def unlink(self, cr, uid, ids, context=None):
|
||||
temp = self.read(cr, uid, ids,context=context)
|
||||
unlink_ids = []
|
||||
for t in temp:
|
||||
unlink_ids.append(t['id'])
|
||||
osv.osv.unlink(self, cr, uid, unlink_ids, context=context)
|
||||
return True
|
||||
|
||||
|
||||
|
||||
def _get_uom_id(self, cr, uid, *args):
|
||||
cr.execute('select id from product_uom order by id limit 1')
|
||||
res = cr.fetchone()
|
||||
|
@ -482,6 +492,19 @@ class product_product(osv.osv):
|
|||
'pricelist_id': fields.dummy(string='Pricelist', relation='product.pricelist', type='many2one'),
|
||||
'name_template': fields.related('product_tmpl_id', 'name', string="Name", type='char', size=128, store=True),
|
||||
}
|
||||
|
||||
def unlink(self, cr, uid, ids, context=None):
|
||||
unlink_ids = []
|
||||
unlink_product_tmpl_ids = []
|
||||
for product in self.browse(cr, uid, ids, context=context):
|
||||
tmpl_id = product.product_tmpl_id.id
|
||||
# Check if the product is last product of this template
|
||||
other_product_ids = self.search(cr, uid, [('product_tmpl_id', '=', tmpl_id), ('id', '!=', product.id)], context=context)
|
||||
if not other_product_ids:
|
||||
unlink_product_tmpl_ids.append(tmpl_id)
|
||||
unlink_ids.append(product.id)
|
||||
self.pool.get('product.template').unlink(cr, uid, unlink_product_tmpl_ids, context=context)
|
||||
return super(product_product, self).unlink(cr, uid, unlink_ids, context=context)
|
||||
|
||||
def onchange_uom(self, cursor, user, ids, uom_id,uom_po_id):
|
||||
if uom_id and uom_po_id:
|
||||
|
|
Loading…
Reference in New Issue