Prevent modify opportunity origin of sales
This must be prevented otherwise the opportunity may stay in "converted" state. issue9916 review339671002
This commit is contained in:
1 parent
8aae1f6319
commit
b57bc89b57
2 files changed
+20
No files matched your search
@@ -6,5 +6,8 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<record model="ir.message" id="msg_opportunity_delete_cancel">
|
||||
<field name="text">To delete opportunity "%(opportunity)s", you must cancel it.</field>
|
||||
</record>
|
||||
<record model="ir.message" id="msg_modify_origin_opportunity">
|
||||
<field name="text">You cannot modify the opportunity origin of the sale "%(sale)s".</field>
|
||||
</record>
|
||||
</data>
|
||||
</tryton>
|
||||
@@ -2,6 +2,8 @@
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
from functools import wraps
|
||||
|
||||
from trytond.i18n import gettext
|
||||
from trytond.model.exceptions import AccessError
|
||||
from trytond.pool import PoolMeta, Pool
|
||||
from trytond.transaction import Transaction
|
||||
|
||||
@@ -27,6 +29,21 @@ class Sale(metaclass=PoolMeta):
|
||||
def _get_origin(cls):
|
||||
return super(Sale, cls)._get_origin() + ['sale.opportunity']
|
||||
|
||||
@classmethod
|
||||
def write(cls, *args):
|
||||
pool = Pool()
|
||||
Opportunity = pool.get('sale.opportunity')
|
||||
actions = iter(args)
|
||||
for sales, values in zip(actions, actions):
|
||||
if 'origin' in values:
|
||||
for sale in sales:
|
||||
if isinstance(sale.origin, Opportunity):
|
||||
raise AccessError(gettext(
|
||||
'sale_opportunity'
|
||||
'.msg_modify_origin_opportunity',
|
||||
sale=sale.rec_name))
|
||||
super().write(*args)
|
||||
|
||||
@classmethod
|
||||
@process_opportunity
|
||||
def delete(cls, sales):
|
||||
|
||||
Reference in new issue
Block a user