Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
3 Odpowiedzi
2466 Widoki

Can I get the cheapest price for a product (e.g. book) quoted by different vendors using lambda or any other alternative

store maybe somewhere showing vendor x was the cheapest for product book.


I have tried searching for an answer in Odoo community but with fail.

I will appreciate any help. I'm really stuck.

Awatar
Odrzuć
Najlepsza odpowiedź

Hello, Leonard. Shivoham's answer can serve as an suggestion for you. I have another way. Isn't your goal to discover the cheapest product? Assume you have attributes 'name,' 'price,' and 'vendor id' in the model 'product.'
You can 'group_by' all of its records by name, and see which record has the lowest 'price.'
You'll know which vendor provides that product thanks to the field 'vendor id.'

Awatar
Odrzuć
Autor Najlepsza odpowiedź

Thanks for the response Shivoham,

I have tried many for loops but they seem not work.

The below code is what I was trying to do.

def compute_cheapest(self):
for rec in self:
partner = rec.env['purchase.order'].search([('partner_id', '=', rec.partner_id.id)])
for each_partner in partner:
line = each_partner.order_line
for item in line:
if item.product_id._________________:


item.write({'quality': True})
else:
item.write({'quality': False})

The place where I have put the dash is where I am stuck. How can I search in every vendor's oder_line and find similar products quoted by them. The cheapest price for that product I do the last code which I have written:

NB: I have set field quality to Boolean that's why in the end I am writting "True" or "False"

....
item.write({'quality': True})
else: item.write({'quality': False})

Or is there a better way to do it

Awatar
Odrzuć
Najlepsza odpowiedź

Hello Leonard, 

You have to use loop in product vendor's list and take the minimum price from that and set it to order line. 

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
3
kwi 22
26338
1
gru 19
3321
0
gru 23
1299
1
lut 21
3956
Odoo Features Rozwiązane
6
gru 23
18726