changeset d6b50e5b653d in modules/sale_opportunity:default
details:
https://hg.tryton.org/modules/sale_opportunity?cmd=changeset;node=d6b50e5b653d
description:
Prevent modify opportunity origin of sales
This must be prevented otherwise the opportunity may stay in
"converted" state.
issue9916
review339671002
diffstat:
message.xml | 3 +++
sale.py | 17 +++++++++++++++++
2 files changed, 20 insertions(+), 0 deletions(-)
diffs (46 lines):
diff -r 3bb5caa909ea -r d6b50e5b653d message.xml
--- a/message.xml Sat Dec 19 17:08:46 2020 +0100
+++ b/message.xml Fri Jan 29 00:06:52 2021 +0100
@@ -6,5 +6,8 @@
<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>
diff -r 3bb5caa909ea -r d6b50e5b653d sale.py
--- a/sale.py Sat Dec 19 17:08:46 2020 +0100
+++ b/sale.py Fri Jan 29 00:06:52 2021 +0100
@@ -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
@@ -28,6 +30,21 @@
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):
super(Sale, cls).delete(sales)