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

hello, i am trying to restrict sales order confirmation by checking if the specified quantity within the order lines is available in the inventory.

for example if someone using the sales module wants to create a quotation and selects a product and sets quantity to 1,000 but there are only 900 units in the inventory i want it to reject this sales order or maybe even trigger an error.

thanks 

p.s. im using odoo 15

Awatar
Odrzuć
Najlepsza odpowiedź

Hi,

Try to refer the following code.

from odoo import models, api, exceptions

class SaleOrder(models.Model):

    _inherit = 'sale.order'

    def action_confirm(self):

        for line in self.order_line:

            product_qty_available = line.product_id.qty_available

            if product_qty_available < line.product_uom_qty:

                raise exceptions.Warning('Not enough stock available for product %s. Available quantity: %s' % (line.product_id.name, product_qty_available))

        return super(SaleOrder, self).action_confirm()


Hope it helps


Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
3
lut 25
1950
1
gru 24
2092
2
mar 24
2430
2
mar 24
2968
0
wrz 23
1520