details:   https://code.tryton.org/tryton/commit/c9b9d8b75bad
branch:    default
user:      Cédric Krier <[email protected]>
date:      Wed Nov 19 12:22:51 2025 +0100
description:
        Prevent running create quotation wizard from request in not allowed 
state

        Using a button we can prevent to use the wizard on purchase request 
with a not
        allowed state.
diffstat:

 modules/purchase_request_quotation/CHANGELOG                                   
  |   1 +
 modules/purchase_request_quotation/purchase.py                                 
  |  13 +++++++
 modules/purchase_request_quotation/purchase.xml                                
  |  17 +++++++--
 
modules/purchase_request_quotation/tests/scenario_purchase_request_quotation.rst
 |  10 ++---
 modules/purchase_request_quotation/view/purchase_request_list.xml              
  |   8 ++++
 5 files changed, 38 insertions(+), 11 deletions(-)

diffs (125 lines):

diff -r 30e74b413c43 -r c9b9d8b75bad 
modules/purchase_request_quotation/CHANGELOG
--- a/modules/purchase_request_quotation/CHANGELOG      Wed Nov 19 12:22:17 
2025 +0100
+++ b/modules/purchase_request_quotation/CHANGELOG      Wed Nov 19 12:22:51 
2025 +0100
@@ -1,3 +1,4 @@
+* Prevent running create quotation wizard from request in not allowed state
 * Allow creating quotation from request in received state
 * Open requests for quotations created from wizard
 
diff -r 30e74b413c43 -r c9b9d8b75bad 
modules/purchase_request_quotation/purchase.py
--- a/modules/purchase_request_quotation/purchase.py    Wed Nov 19 12:22:17 
2025 +0100
+++ b/modules/purchase_request_quotation/purchase.py    Wed Nov 19 12:22:51 
2025 +0100
@@ -627,6 +627,13 @@
         for s in selection:
             if s not in cls.state.selection:
                 cls.state.selection.append(s)
+        cls._buttons.update({
+                'create_quotation': {
+                    'invisible': Eval('state').in_(
+                        ['draft', 'quotation', 'received']),
+                    'depends': ['state'],
+                    },
+                })
 
     def get_state(self):
         state = super().get_state()
@@ -637,6 +644,12 @@
                 state = 'received'
         return state
 
+    @classmethod
+    @ModelView.button_action(
+        'purchase_request_quotation.wizard_create_quotation')
+    def create_quotation(cls, requests):
+        pass
+
 
 class CreatePurchase(Wizard):
     __name__ = 'purchase.request.create_purchase'
diff -r 30e74b413c43 -r c9b9d8b75bad 
modules/purchase_request_quotation/purchase.xml
--- a/modules/purchase_request_quotation/purchase.xml   Wed Nov 19 12:22:17 
2025 +0100
+++ b/modules/purchase_request_quotation/purchase.xml   Wed Nov 19 12:22:51 
2025 +0100
@@ -100,11 +100,6 @@
             <field name="name">Create Quotation</field>
             <field name="wiz_name">purchase.request.quotation.create</field>
         </record>
-        <record model="ir.action.keyword" id="create_quotation_keyword">
-            <field name="keyword">form_action</field>
-            <field name="model">purchase.request,-1</field>
-            <field name="action" ref="wizard_create_quotation"/>
-        </record>
         <record model="ir.action-res.group" 
id="wizard_create_quotation_group_purchase_request">
             <field name="action" ref="wizard_create_quotation"/>
             <field name="group" ref="purchase_request.group_purchase_request"/>
@@ -176,6 +171,18 @@
             <field name="name">purchase_request_form</field>
         </record>
 
+        <record model="ir.ui.view" id="purchase_request_view_list">
+            <field name="model">purchase.request</field>
+            <field name="inherit" 
ref="purchase_request.purchase_request_view_tree"/>
+            <field name="name">purchase_request_list</field>
+        </record>
+
+        <record model="ir.model.button" 
id="purchase_request_create_quotation_button">
+            <field name="model">purchase.request</field>
+            <field name="name">create_quotation</field>
+            <field name="string">Create Quotations</field>
+        </record>
+
         <record model="ir.ui.view"
             id="purchase_configuration_view_form">
             <field name="model">purchase.configuration</field>
diff -r 30e74b413c43 -r c9b9d8b75bad 
modules/purchase_request_quotation/tests/scenario_purchase_request_quotation.rst
--- 
a/modules/purchase_request_quotation/tests/scenario_purchase_request_quotation.rst
  Wed Nov 19 12:22:17 2025 +0100
+++ 
b/modules/purchase_request_quotation/tests/scenario_purchase_request_quotation.rst
  Wed Nov 19 12:22:51 2025 +0100
@@ -7,7 +7,7 @@
     >>> import datetime as dt
     >>> from decimal import Decimal
 
-    >>> from proteus import Model, Report, Wizard
+    >>> from proteus import Model, Report
     >>> from trytond.modules.account.tests.tools import create_chart, 
get_accounts
     >>> from trytond.modules.company.tests.tools import create_company
     >>> from trytond.tests.tools import activate_modules, assertEqual, set_user
@@ -103,8 +103,7 @@
     >>> purchase_request, = PurchaseRequest.find([('state', '=', 'draft')])
     >>> purchase_request.state
     'draft'
-    >>> create_quotation = Wizard(
-    ...     'purchase.request.quotation.create', [purchase_request])
+    >>> create_quotation = purchase_request.click('create_quotation')
     >>> assertEqual(create_quotation.form.suppliers, [supplier])
     >>> create_quotation.form.suppliers.append(Party(supplier2.id))
     >>> create_quotation.execute('create_quotations')
@@ -173,7 +172,7 @@
 Create Purchase Order from Purchase Request and check if supplier with
 best price from quotations was selected (supplier2 price)::
 
-    >>> create_purchase = Wizard('purchase.request.create_purchase', 
[prequest])
+    >>> create_purchase = prequest.click('create_purchase')
     >>> prequest.state
     'purchased'
     >>> Purchase = Model.get('purchase.purchase')
@@ -187,8 +186,7 @@
 Create Purchase Order from Purchase Request having a preferred_quotation_line
 and check if supplier from this quotation was selected::
 
-    >>> create_purchase = Wizard('purchase.request.create_purchase',
-    ...     [prequest2])
+    >>> create_purchase = prequest2.click('create_purchase')
     >>> prequest2.state
     'purchased'
     >>> Purchase = Model.get('purchase.purchase')
diff -r 30e74b413c43 -r c9b9d8b75bad 
modules/purchase_request_quotation/view/purchase_request_list.xml
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/purchase_request_quotation/view/purchase_request_list.xml Wed Nov 
19 12:22:51 2025 +0100
@@ -0,0 +1,8 @@
+<?xml version="1.0"?>
+<!-- This file is part of Tryton.  The COPYRIGHT file at the top level of
+this repository contains the full copyright notices and license terms. -->
+<data>
+    <xpath expr="/tree" position="inside">
+        <button name="create_quotation" multiple="1"/>
+    </xpath>
+</data>

Reply via email to