Cédric Krier pushed to branch branch/default at Tryton / Tryton


Commits:
f783ef63 by Cédric Krier at 2023-03-23T17:37:17+01:00
Remove salable constraint on product when quantity is negative

Closes #9057
- - - - -
48170104 by Cédric Krier at 2023-03-23T17:37:34+01:00
Remove purchasable constraint on product when quantity is negative

Closes #9057
- - - - -


8 changed files:

- modules/purchase/purchase.py
- modules/purchase_amendment/purchase.py
- modules/purchase_request/purchase_request.py
- modules/purchase_requisition/purchase.py
- modules/sale/sale.py
- modules/sale_amendment/sale.py
- modules/sale_opportunity/opportunity.py
- modules/sale_point/sale.py


Changes:

=====================================
modules/purchase/purchase.py
=====================================
@@ -1116,9 +1116,10 @@
     product = fields.Many2One('product.product', 'Product',
         ondelete='RESTRICT',
         domain=[
-            If(Eval('purchase_state').in_(['draft', 'quotation']),
-                [('purchasable', '=', True)],
-                []),
+            If(Eval('purchase_state').in_(['draft', 'quotation'])
+                & ~(Eval('quantity', 0) < 0),
+                ('purchasable', '=', True),
+                ()),
             If(Eval('type') != 'line',
                 ('id', '=', None),
                 ()),


=====================================
modules/purchase_amendment/purchase.py
=====================================
@@ -245,7 +245,8 @@
     product = fields.Many2One(
         'product.product', "Product",
         domain=[
-            If(Eval('state') == 'draft',
+            If((Eval('state') == 'draft')
+                & ~(Eval('quantity', 0) < 0),
                 ('purchasable', '=', True),
                 ()),
             If(Eval('product_uom_category'),


=====================================
modules/purchase_request/purchase_request.py
=====================================
@@ -28,7 +28,12 @@
 
     product = fields.Many2One(
         'product.product', "Product", readonly=True,
-        domain=[('purchasable', '=', True)],
+        domain=[
+            If((Eval('state') == 'draft')
+                & ~(Eval('quantity', 0) < 0),
+                ('purchasable', '=', True),
+                ()),
+            ],
         context={
             'company': Eval('company', -1),
             },


=====================================
modules/purchase_requisition/purchase.py
=====================================
@@ -445,7 +445,10 @@
         'product.product', 'Product',
         ondelete='RESTRICT',
         domain=[
-            ('purchasable', '=', True),
+            If((Eval('purchase_requisition_state') == 'draft')
+                & ~(Eval('quantity', 0) < 0),
+                ('purchasable', '=', True),
+                ()),
             ],
         states=_states)
     product_uom_category = fields.Function(


=====================================
modules/sale/sale.py
=====================================
@@ -1201,7 +1201,8 @@
     product = fields.Many2One('product.product', 'Product',
         ondelete='RESTRICT',
         domain=[
-            If(Eval('sale_state').in_(['draft', 'quotation']),
+            If(Eval('sale_state').in_(['draft', 'quotation'])
+                & ~(Eval('quantity', 0) < 0),
                 ('salable', '=', True),
                 ()),
             If(Eval('type') != 'line',


=====================================
modules/sale_amendment/sale.py
=====================================
@@ -282,7 +282,8 @@
     product = fields.Many2One(
         'product.product', "Product",
         domain=[
-            If(Eval('state') == 'draft',
+            If((Eval('state') == 'draft')
+                & ~(Eval('quantity', 0) < 0),
                 ('salable', '=', True),
                 ()),
             If(Eval('product_uom_category'),


=====================================
modules/sale_opportunity/opportunity.py
=====================================
@@ -569,7 +569,13 @@
         fields.Selection('get_opportunity_states', "Opportunity State"),
         'on_change_with_opportunity_state')
     product = fields.Many2One('product.product', 'Product', required=True,
-        domain=[('salable', '=', True)], states=_states)
+        domain=[
+            If(Eval('opportunity_state').in_(['lead', 'opportunity'])
+                & ~(Eval('quantity', 0) < 0),
+                ('salable', '=', True),
+                ()),
+            ],
+        states=_states)
     quantity = fields.Float(
         "Quantity", digits='unit', required=True, states=_states)
     unit = fields.Many2One('product.uom', 'Unit', required=True,


=====================================
modules/sale_point/sale.py
=====================================
@@ -456,7 +456,10 @@
     product = fields.Many2One(
         'product.product', "Product", required=True,
         domain=[
-            ('salable', '=', True),
+            If((Eval('sale_state') == 'open')
+                & ~(Eval('quantity', 0) < 0),
+                ('salable', '=', True),
+                ()),
             ],
         context={
             'company': Eval('company'),



View it on Heptapod: 
https://foss.heptapod.net/tryton/tryton/-/compare/a0a839acdd040d4cdd15fd0e4fcb8957f003c083...481701049f6e1535286fc7963de45212f9b77113

-- 
View it on Heptapod: 
https://foss.heptapod.net/tryton/tryton/-/compare/a0a839acdd040d4cdd15fd0e4fcb8957f003c083...481701049f6e1535286fc7963de45212f9b77113
You're receiving this email because of your account on foss.heptapod.net.


Reply via email to