Skip to Content
Menu
This question has been flagged
1 Reply
2929 Views

class item(models.Model):    

_name = 'item'  

 #_inherit = 'technical'

 product = fields.Many2one('product.product', string='Product Name' ,change_default=True)

 qty_deliver = fields.Integer(compute="_qtydelivery", string='Quantity Delivered')

----------------------------------------------------------------------------------

@api.one   

 def _qtydelivery(self):      

      if self.product == delivery_technical .product_technical:         

           self.qty_delivered = delivery_technical .product_qty_delivered

----------------------------------------------------------------------------------

class delivery_technical(models.Model):   

 _name = 'technical'


 product_technical = fields.Many2one('product.product', string='Product Name' ,change_default=True,) 

 product_qty_delivered = fields.Integer(string='Quantity Delivered')     


 I want the function if the products in both classes were equal to the field value of the  qty_delivere.

 I used inheritance but it was error  .

please help me.

Avatar
Discard
Best Answer

Hi Sana,

To make a conditional with a field for another class, you first need to get a record of that other class. So for example:

@api.multi   
def _qtydelivery(self):
# The use of @api.one is discouraged, better use @api.multi and then check self.ensure_one() to ensue you got just one record
self.ensure_one()
# Now you need the record of the other class you want to compare, so for example
        technical_id = self.env['technical'].search([('name', '=', 'some_name...')], limit=1)
if self.product == technical_id.product_technical:
self.qty_delivered = technical_id.product_qty_delivered

Same like that should work. Other option would be to have for example a Many2one field in the 'item' class with a relation to some record of the model 'technical'. In that case you should just compare more or less like you were doing before.

class item(models.Model):    

_name = 'item'
_description = "Item..."

product = fields.Many2one('product.product', string='Product Name' ,change_default=True)
qty_deliver = fields.Integer(compute="_qtydelivery", string='Quantity Delivered')
technical_id = fields.Many2one('technical', string="Technical")

@api.multi
def _qtydelivery(self):
# The use of @api.one is discouraged, better use @api.multi and then check self.ensure_one() to ensue you got just one record
self.ensure_one()
if self.product == self.technical_id.product_technical:
self.qty_delivered = self.technical_id.product_qty_delivered


Hope it can help you or maybe other people :) 

Avatar
Discard
Author

Thank you