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
1576 Widoki

Hello,

I want to prevent the sale of a product if it reaches a specific quantity odoo 17

Awatar
Odrzuć
Najlepsza odpowiedź

Hello,


To prevent the sale of a product if it reaches a specific quantity in Odoo 17, you can achieve this by creating a custom module or by using server actions and automated actions to enforce this restriction. Here’s a step-by-step guide on how you can implement this using a custom module approach:


1. Create a new model file for the product extension:


  from odoo import models, fields


  class ProductTemplate(models.Model):

      _inherit = 'product.template'


      min_qty = fields.Float(string='Minimum Quantity', default=0.0, help='Minimum quantity for the product to trigger the restriction.')


2. Define the sale order model:


  from odoo import models, fields, api, _

  from odoo.exceptions import UserError


  class SaleOrderLine(models.Model):

      _inherit = 'sale.order.line'


      @api.constrains('product_uom_qty')

      def _check_product_quantity(self):

          for line in self:

              if line.product_id.qty_available

                  raise UserError(_(

                      'You cannot sell this product because it has reached the minimum quantity limit: %s' % line.product_id.name))


This will prevent the sale of a product if it reaches a specific quantity by checking the available quantity against a defined minimum quantity for the product. If the available quantity is less than or equal to the minimum quantity, an error will be raised, preventing the sale.


Hope it helps.

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
1
sie 25
300
0
cze 24
1679
4
cze 24
3734
0
mar 24
1755
2
sty 24
2128