Odoo Help

0

0
1 Answer
1
Avatar

Jose David Moreno Hernandez Spain

--Jose David Moreno Hernandez--

4429
| 4 1 4
Málaga, Spain
--Jose David Moreno Hernandez--


Jose David Moreno Hernandez Spain
02:32, 09/11/2019

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 :) 

1 Comment
sana India
02:36, 09/11/2019

Thank you

Ask a Question
Writer
Keep Informed
1 follower(s)
About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register
Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now