Skip to content

Commit cb1c64c

Browse files
Ernesto Tejedaschhatbar-initos
Ernesto Tejeda
authored andcommitted
[IMP] chained_swapper: env, date and datetime in constraint expression.
1 parent 027e482 commit cb1c64c

File tree

6 files changed

+14
-6
lines changed

6 files changed

+14
-6
lines changed

chained_swapper/README.rst

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ To configure this module, you need to:
6969

7070
`any(p.state == 'done' for p in records.mapped('picking_ids.state'))`
7171

72+
Other variables you can use are `env`, `date` and `datetime`.
7273
Each constraint has a name for identifying it, but also for showing that
7374
name when displaying the error trying to do the swap.
7475

chained_swapper/i18n/chained_swapper.pot

+2-4
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ msgid ""
66
msgstr ""
77
"Project-Id-Version: Odoo Server 12.0\n"
88
"Report-Msgid-Bugs-To: \n"
9-
"POT-Creation-Date: 2020-08-14 10:32+0000\n"
10-
"PO-Revision-Date: 2020-08-14 10:32+0000\n"
119
"Last-Translator: <>\n"
1210
"Language-Team: \n"
1311
"MIME-Version: 1.0\n"
@@ -16,7 +14,7 @@ msgstr ""
1614
"Plural-Forms: \n"
1715

1816
#. module: chained_swapper
19-
#: code:addons/chained_swapper/wizard/chained_swapper_wizard.py:138
17+
#: code:addons/chained_swapper/wizard/chained_swapper_wizard.py:146
2018
#, python-format
2119
msgid "<b>Chained swap done</b>:"
2220
msgstr ""
@@ -218,7 +216,7 @@ msgid "Name"
218216
msgstr ""
219217

220218
#. module: chained_swapper
221-
#: code:addons/chained_swapper/wizard/chained_swapper_wizard.py:25
219+
#: code:addons/chained_swapper/wizard/chained_swapper_wizard.py:32
222220
#, python-format
223221
msgid "Not possible to swap the field due to the constraint"
224222
msgstr ""

chained_swapper/readme/CONFIGURE.rst

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ To configure this module, you need to:
2020

2121
`any(p.state == 'done' for p in records.mapped('picking_ids.state'))`
2222

23+
Other variables you can use are `env`, `date` and `datetime`.
2324
Each constraint has a name for identifying it, but also for showing that
2425
name when displaying the error trying to do the swap.
2526

9.23 KB
Loading

chained_swapper/static/description/index.html

+2-1
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,8 @@ <h1><a class="toc-backref" href="#id1">Configuration</a></h1>
419419
will be referring the selected records for doing the swap. Example: for
420420
restricting sales orders that have a delivery order validated:</p>
421421
<p><cite>any(p.state == ‘done’ for p in records.mapped(‘picking_ids.state’))</cite></p>
422-
<p>Each constraint has a name for identifying it, but also for showing that
422+
<p>Other variables you can use are <cite>env</cite>, <cite>date</cite> and <cite>datetime</cite>.
423+
Each constraint has a name for identifying it, but also for showing that
423424
name when displaying the error trying to do the swap.</p>
424425
</li>
425426
</ul>

chained_swapper/wizard/chained_swapper_wizard.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
33

44
from lxml import etree
5+
from datetime import date, datetime
56

67
from odoo.tools.safe_eval import safe_eval
78
from odoo import _, api, models
@@ -18,10 +19,16 @@ def default_get(self, fields):
1819
if context.get('chained_swapper_id'):
1920
records = self.env[context.get('active_model')].browse(
2021
context.get('active_ids'))
22+
exp_dict = {
23+
'records': records,
24+
'env': self.env,
25+
'date': date,
26+
'datetime': datetime,
27+
}
2128
chained_swapper = self.env['chained.swapper'].browse(
2229
context.get('chained_swapper_id'))
2330
for constraint in chained_swapper.constraint_ids:
24-
if safe_eval(constraint.expression, {'records': records}):
31+
if safe_eval(constraint.expression, exp_dict):
2532
raise UserError(_(
2633
"Not possible to swap the field due to the constraint"
2734
) + ": " + constraint.name)

0 commit comments

Comments
 (0)