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.
This commit is contained in:
Cédric Krier
2025-11-19 12:22:51 +01:00
parent c50d717dd7
commit 67b01f6cc3
5 changed files with 38 additions and 11 deletions
@@ -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
@@ -627,6 +627,13 @@ class PurchaseRequest(metaclass=PoolMeta):
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 @@ class PurchaseRequest(metaclass=PoolMeta):
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'
@@ -100,11 +100,6 @@ this repository contains the full copyright notices and license terms. -->
<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 @@ this repository contains the full copyright notices and license terms. -->
<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>
@@ -7,7 +7,7 @@ Imports::
>>> 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 @@ add another supplier::
>>> 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 @@ with a quotation not having the minimum price unit::
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 @@ best price from quotations was selected (supplier2 price)::
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')
@@ -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>