Siirry sisältöön
Menu
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Tämä kysymys on merkitty
2 Vastaukset
2379 Näkymät

i have model purchase.request the user enter product line in line_ids one2many field for  this model the user can create purchase order with products inserted in the line_ids in purchase.request model, the user can delete one line from order_lines in purchase,order.

how can i check if the line_ids from purchase.request model is existing in order_line in purchase.order model,

i have 3 model:

purchase.request.line linked with purchase.request using request_id.

and purchase.order linked with purchase.request using request_ids many2many field.

i try this code:

for rec in self:
purchase_orders = self.env['purchase.order'].search([('request_ids', 'in', rec.id)])
for order_line in purchase_orders.order_line:
for line in rec.line_ids:
if line.product_id in order_line:
rec.line_ids.purchase_state = 'rfq'

but i get below error:

TypeError: Mixing apples and oranges: product.product(1549,) in purchase.order.line(1570,)


Thanks .....

Avatar
Hylkää
Paras vastaus

Hi,

The error is beacuse you are trying to check if product_id is existing in order line object,

Replace your condition as below: 


Hope this will help you
Thank you

Avatar
Hylkää
Tekijä

Thank you for replay but i am still getting error :
TypeError: Mixing apples and oranges: 617 in purchase.order.line(1683,)

Paras vastaus

Hello Loay elhaj,

You can used bellow example. 

Please find code in comment. 

I hope this will be helpful.

Thanks & Regards,
Email: odoo@aktivsoftware.com
Skype: kalpeshmaheshwari 

Avatar
Hylkää

for rec in self:
purchase_orders = self.env['purchase.order'].search([('request_ids', 'in', rec.id)])
for order_line in purchase_orders.order_line:
for line in rec.line_ids:

# check condition for if purchase order line product and line product id.
if order_line.product_id == line.product_id.id:
line.purchase_state = 'rfq'

Or used billow code..

product = order_line.filtered(lambda x: x.product_id == line.product_id.id):
if product:
line.purchase_state = 'rfq'

Tekijä

Thanks but its showing:
Comparing apples and oranges: product.product(351,) == 665

Aiheeseen liittyviä artikkeleita Vastaukset Näkymät Toimenpide
1
heinäk. 22
2569
0
huhtik. 22
2599
1
jouluk. 21
3895
1
tammik. 21
7216
1
jouluk. 20
3558