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

Hello,

Previously in the purchase order more than 100 products are entered, many times the user is equipment and orders twice the same product, how can I solve it?

Something that blocks me if they repeat themselves or give me a warning?

Awatar
Odrzuć
Najlepsza odpowiedź

Hi,

You can use sql constrains for this,

_sql_constraints = [
    ('Unique product', 'unique(order_id,product_id)', 'duplicate order line exists'),
    ]

Thanks

Awatar
Odrzuć
Autor

Hello, thanks for the answer. this line in which part of the code should I add? Thank you.

Najlepsza odpowiedź

Dear Eduardo,

To check exist the same Product in the line level.

from odoo import models, fields, api
from odoo.exceptions import ValidationError


class PurchaseOrder(models.Model):
_inherit = "purchase.order"

@api.multi
@api.constrains('order_line')
def _check_exist_product_in_line(self):
for purchase in self:
exist_product_list = []
for line in purchase.order_line:
if line.product_id.id in exist_product_list:
raise ValidationError(_('Product should be one per line.'))
exist_product_list.append(line.product_id.id)

Hope this code help you

Best Thanks,

Ankit H Gandhi.


Awatar
Odrzuć
Autor Najlepsza odpowiedź

Hello, thanks for the answer. this line in which part of the code should I add? Thank you.

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
2
maj 25
1964
3
mar 25
1568
2
sty 24
3424
0
lis 23
2073
0
wrz 23
1864