[tryton-commits] changeset in trytond:6.0 Use normalized length of record name

2021-12-23 Thread Adrià Tarroja Caubet
changeset 846c65ac0270 in trytond:6.0
details: https://hg.tryton.org/trytond?cmd=changeset=846c65ac0270
description:
Use normalized length of record name

This is needed in case the client normalize the report name before 
storing to
the filesystem.

issue10986
review381471003
(grafted from 970256a66ba01885af777a2fe13052f9664ba4c1)
diffstat:

 trytond/report/report.py |  4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diffs (21 lines):

diff -r 8cefcbc7a0d5 -r 846c65ac0270 trytond/report/report.py
--- a/trytond/report/report.py  Thu Dec 16 22:12:42 2021 +0100
+++ b/trytond/report/report.py  Sat Dec 18 01:37:06 2021 +0100
@@ -9,6 +9,7 @@
 import subprocess
 import tempfile
 import time
+import unicodedata
 import warnings
 import zipfile
 import operator
@@ -163,7 +164,8 @@
 - len(str(record_count)) - 2)
 for record in records[:5]:
 record_name = record.rec_name
-name_length += len(record_name) + 1
+name_length += len(
+unicodedata.normalize('NFKD', record_name)) + 1
 if name_length > max_length:
 break
 names.append(record_name)



[tryton-commits] changeset in trytond:6.2 Use normalized length of record name

2021-12-23 Thread Adrià Tarroja Caubet
changeset 205b4030b93c in trytond:6.2
details: https://hg.tryton.org/trytond?cmd=changeset=205b4030b93c
description:
Use normalized length of record name

This is needed in case the client normalize the report name before 
storing to
the filesystem.

issue10986
review381471003
(grafted from 970256a66ba01885af777a2fe13052f9664ba4c1)
diffstat:

 trytond/report/report.py |  4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diffs (21 lines):

diff -r 8f0eb6f2e910 -r 205b4030b93c trytond/report/report.py
--- a/trytond/report/report.py  Thu Dec 16 22:12:42 2021 +0100
+++ b/trytond/report/report.py  Sat Dec 18 01:37:06 2021 +0100
@@ -9,6 +9,7 @@
 import subprocess
 import tempfile
 import time
+import unicodedata
 import warnings
 import zipfile
 import operator
@@ -173,7 +174,8 @@
 record_name = template.generate(record=record).render()
 else:
 record_name = record.rec_name
-name_length += len(record_name) + 1
+name_length += len(
+unicodedata.normalize('NFKD', record_name)) + 1
 if name_length > max_length:
 break
 names.append(record_name)



[tryton-commits] changeset in trytond:5.0 Clear transaction cache after commit

2021-12-23 Thread Cédric Krier
changeset fc7e69e4e0e8 in trytond:5.0
details: https://hg.tryton.org/trytond?cmd=changeset=fc7e69e4e0e8
description:
Clear transaction cache after commit

If there are multiple commits, the data in the database may have been 
modified.

issue11014
review381481003
(grafted from f23258f695042a5958e53f54de153ccdda541121)
diffstat:

 trytond/transaction.py |  2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diffs (12 lines):

diff -r 0094c39d870b -r fc7e69e4e0e8 trytond/transaction.py
--- a/trytond/transaction.pyFri Dec 03 21:43:28 2021 +0100
+++ b/trytond/transaction.pyThu Dec 16 22:12:42 2021 +0100
@@ -207,6 +207,8 @@
 datamanager.commit(self)
 for datamanager in self._datamanagers:
 datamanager.tpc_vote(self)
+for cache in self.cache.values():
+cache.clear()
 self.connection.commit()
 except:
 self.rollback()



[tryton-commits] changeset in trytond:6.0 Clear transaction cache after commit

2021-12-23 Thread Cédric Krier
changeset 8cefcbc7a0d5 in trytond:6.0
details: https://hg.tryton.org/trytond?cmd=changeset=8cefcbc7a0d5
description:
Clear transaction cache after commit

If there are multiple commits, the data in the database may have been 
modified.

issue11014
review381481003
(grafted from f23258f695042a5958e53f54de153ccdda541121)
diffstat:

 trytond/transaction.py |  2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diffs (12 lines):

diff -r dcffa7963249 -r 8cefcbc7a0d5 trytond/transaction.py
--- a/trytond/transaction.pyFri Dec 03 21:42:56 2021 +0100
+++ b/trytond/transaction.pyThu Dec 16 22:12:42 2021 +0100
@@ -223,6 +223,8 @@
 for datamanager in self._datamanagers:
 datamanager.tpc_vote(self)
 self.started_at = self.monotonic_time()
+for cache in self.cache.values():
+cache.clear()
 Cache.commit(self)
 self.connection.commit()
 except Exception:



[tryton-commits] changeset in trytond:6.2 Clear transaction cache after commit

2021-12-23 Thread Cédric Krier
changeset 8f0eb6f2e910 in trytond:6.2
details: https://hg.tryton.org/trytond?cmd=changeset=8f0eb6f2e910
description:
Clear transaction cache after commit

If there are multiple commits, the data in the database may have been 
modified.

issue11014
review381481003
(grafted from f23258f695042a5958e53f54de153ccdda541121)
diffstat:

 trytond/transaction.py |  2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diffs (12 lines):

diff -r 33dcdd3129a7 -r 8f0eb6f2e910 trytond/transaction.py
--- a/trytond/transaction.pyFri Dec 03 21:42:00 2021 +0100
+++ b/trytond/transaction.pyThu Dec 16 22:12:42 2021 +0100
@@ -237,6 +237,8 @@
 for datamanager in self._datamanagers:
 datamanager.tpc_vote(self)
 self.started_at = self.monotonic_time()
+for cache in self.cache.values():
+cache.clear()
 Cache.commit(self)
 self.connection.commit()
 except Exception:



[tryton-commits] changeset in tryton:6.0 Install gdbus.exe on Windows

2021-12-23 Thread Cédric Krier
changeset 88f19df9372f in tryton:6.0
details: https://hg.tryton.org/tryton?cmd=changeset=88f19df9372f
description:
Install gdbus.exe on Windows

gdbus.exe is needed to have interprocess communication to launch action.

issue11024
review366321002
(grafted from eba089cb041a2cd86836c883fec1408c6bc61135)
diffstat:

 make-win32-installer.sh |  1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diffs (9 lines):

diff -r a741f44e582e -r 88f19df9372f make-win32-installer.sh
--- a/make-win32-installer.sh   Thu Dec 16 22:14:22 2021 +0100
+++ b/make-win32-installer.sh   Thu Dec 16 22:19:38 2021 +0100
@@ -6,4 +6,5 @@
 rm -rf build dist
 ./setup.py compile_catalog
 ./setup-freeze.py install_exe -d dist
+cp `which gdbus.exe` dist/
 makensis -DVERSION=${version} -DSERIES=${series} -DBITS=${bits} setup.nsi



[tryton-commits] changeset in tryton:6.2 Install gdbus.exe on Windows

2021-12-23 Thread Cédric Krier
changeset 61eac0d058ca in tryton:6.2
details: https://hg.tryton.org/tryton?cmd=changeset=61eac0d058ca
description:
Install gdbus.exe on Windows

gdbus.exe is needed to have interprocess communication to launch action.

issue11024
review366321002
(grafted from eba089cb041a2cd86836c883fec1408c6bc61135)
diffstat:

 make-win32-installer.sh |  1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diffs (9 lines):

diff -r 8e6c646ad2c1 -r 61eac0d058ca make-win32-installer.sh
--- a/make-win32-installer.sh   Thu Dec 16 22:14:22 2021 +0100
+++ b/make-win32-installer.sh   Thu Dec 16 22:19:38 2021 +0100
@@ -6,4 +6,5 @@
 rm -rf build dist
 ./setup.py compile_catalog
 ./setup-freeze.py install_exe -d dist
+cp `which gdbus.exe` dist/
 makensis -DVERSION=${version} -DSERIES=${series} -DBITS=${bits} setup.nsi



[tryton-commits] changeset in tryton:5.0 Check screen limit is None before comparing

2021-12-23 Thread Cédric Krier
changeset a2ad41d4984a in tryton:5.0
details: https://hg.tryton.org/tryton?cmd=changeset=a2ad41d4984a
description:
Check screen limit is None before comparing

issue11015
review389361002
(grafted from 2913ea0aaf46c55ad563432a94edbd76a68bc0cd)
diffstat:

 tryton/gui/window/form.py |  1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diffs (11 lines):

diff -r c5c2aa1412e0 -r a2ad41d4984a tryton/gui/window/form.py
--- a/tryton/gui/window/form.py Sun Nov 28 13:47:44 2021 +0100
+++ b/tryton/gui/window/form.py Thu Dec 16 22:14:22 2021 +0100
@@ -485,6 +485,7 @@
 
 msg = name + ' / ' + str(signal_data[1])
 if (signal_data[1] < signal_data[2]
+and self.screen.limit is not None
 and signal_data[2] > self.screen.limit):
 msg += _(' of ') + str(signal_data[2])
 self.status_label.set_text(msg)



[tryton-commits] changeset in tryton:6.0 Check screen limit is None before comparing

2021-12-23 Thread Cédric Krier
changeset a741f44e582e in tryton:6.0
details: https://hg.tryton.org/tryton?cmd=changeset=a741f44e582e
description:
Check screen limit is None before comparing

issue11015
review389361002
(grafted from 2913ea0aaf46c55ad563432a94edbd76a68bc0cd)
diffstat:

 tryton/gui/window/form.py |  1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diffs (11 lines):

diff -r 21266fd82cc7 -r a741f44e582e tryton/gui/window/form.py
--- a/tryton/gui/window/form.py Mon Dec 06 23:37:42 2021 +0100
+++ b/tryton/gui/window/form.py Thu Dec 16 22:14:22 2021 +0100
@@ -641,6 +641,7 @@
 
 msg = name + ' / ' + str(signal_data[1])
 if (signal_data[1] < signal_data[2]
+and self.screen.limit is not None
 and signal_data[2] > self.screen.limit):
 msg += _(' of ') + str(signal_data[2])
 self.status_label.set_text(msg)



[tryton-commits] changeset in tryton:6.2 Check screen limit is None before comparing

2021-12-23 Thread Cédric Krier
changeset 8e6c646ad2c1 in tryton:6.2
details: https://hg.tryton.org/tryton?cmd=changeset=8e6c646ad2c1
description:
Check screen limit is None before comparing

issue11015
review389361002
(grafted from 2913ea0aaf46c55ad563432a94edbd76a68bc0cd)
diffstat:

 tryton/gui/window/form.py |  1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diffs (11 lines):

diff -r 11c3d9a341d0 -r 8e6c646ad2c1 tryton/gui/window/form.py
--- a/tryton/gui/window/form.py Mon Dec 06 23:37:42 2021 +0100
+++ b/tryton/gui/window/form.py Thu Dec 16 22:14:22 2021 +0100
@@ -641,6 +641,7 @@
 
 msg = name + ' / ' + str(signal_data[1])
 if (signal_data[1] < signal_data[2]
+and self.screen.limit is not None
 and signal_data[2] > self.screen.limit):
 msg += _(' of ') + str(signal_data[2])
 self.status_label.set_text(msg)



[tryton-commits] changeset in sao:6.0 Connect from of Between using change event

2021-12-23 Thread Cédric Krier
changeset 4e2f8aee4f9d in sao:6.0
details: https://hg.tryton.org/sao?cmd=changeset=4e2f8aee4f9d
description:
Connect from of Between using change event

We do not use any more tempusdominus so the dp.change event does not 
exist
anymore.

issue11020
review374401005
(grafted from d17fdbfd65e371281675511620c2d434e1f2c4a2)
diffstat:

 src/screen.js |  2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diffs (12 lines):

diff -r 414fdc2183b7 -r 4e2f8aee4f9d src/screen.js
--- a/src/screen.js Thu Dec 16 22:14:22 2021 +0100
+++ b/src/screen.js Thu Dec 16 22:16:01 2021 +0100
@@ -633,7 +633,7 @@
 init: function(format, id) {
 this.format = format;
 Sao.ScreenContainer.BetweenDates._super.init.call(this, id);
-this.from.on('dp.change', this._from_changed.bind(this));
+this.from.change(this._from_changed.bind(this));
 },
 _get_value: function(entry, value) {
 return entry.find('input[type=text]').val();



[tryton-commits] changeset in sao:6.2 Connect from of Between using change event

2021-12-23 Thread Cédric Krier
changeset 3b4ff20f6f1d in sao:6.2
details: https://hg.tryton.org/sao?cmd=changeset=3b4ff20f6f1d
description:
Connect from of Between using change event

We do not use any more tempusdominus so the dp.change event does not 
exist
anymore.

issue11020
review374401005
(grafted from d17fdbfd65e371281675511620c2d434e1f2c4a2)
diffstat:

 src/screen.js |  2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diffs (12 lines):

diff -r 7965517652ff -r 3b4ff20f6f1d src/screen.js
--- a/src/screen.js Thu Dec 16 22:14:22 2021 +0100
+++ b/src/screen.js Thu Dec 16 22:16:01 2021 +0100
@@ -638,7 +638,7 @@
 init: function(format, id) {
 this.format = format;
 Sao.ScreenContainer.BetweenDates._super.init.call(this, id);
-this.from.on('dp.change', this._from_changed.bind(this));
+this.from.change(this._from_changed.bind(this));
 },
 _get_value: function(entry, value) {
 return entry.find('input[type=text]').val();



[tryton-commits] changeset in sao:5.0 Check screen limit is None before comparing

2021-12-23 Thread Cédric Krier
changeset dd1cd9674e54 in sao:5.0
details: https://hg.tryton.org/sao?cmd=changeset=dd1cd9674e54
description:
Check screen limit is None before comparing

issue11015
review389361002
(grafted from 28d16a85ee0d4bb2c7b160e7ee859f7badea216d)
diffstat:

 src/tab.js |  4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diffs (14 lines):

diff -r be71fb440f96 -r dd1cd9674e54 src/tab.js
--- a/src/tab.jsFri Dec 03 21:52:24 2021 +0100
+++ b/src/tab.jsThu Dec 16 22:14:22 2021 +0100
@@ -1137,7 +1137,9 @@
 this.buttons.switch_.prop('disabled',
 this.attributes.view_ids > 1);
 var msg = name + ' / ' + data[1];
-if ((data[1] < data[2]) && (data[2] > this.screen.limit)) {
+if ((data[1] < data[2]) &&
+this.screen.limit !== null &&
+(data[2] > this.screen.limit)) {
 msg += Sao.i18n.gettext(' of ') + data[2];
 }
 this.status_label.text(msg).attr('title', msg);



[tryton-commits] changeset in sao:6.0 Check screen limit is None before comparing

2021-12-23 Thread Cédric Krier
changeset 414fdc2183b7 in sao:6.0
details: https://hg.tryton.org/sao?cmd=changeset=414fdc2183b7
description:
Check screen limit is None before comparing

issue11015
review389361002
(grafted from 28d16a85ee0d4bb2c7b160e7ee859f7badea216d)
diffstat:

 src/tab.js |  4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diffs (14 lines):

diff -r 859d97cfec1a -r 414fdc2183b7 src/tab.js
--- a/src/tab.jsFri Dec 03 21:52:02 2021 +0100
+++ b/src/tab.jsThu Dec 16 22:14:22 2021 +0100
@@ -1482,7 +1482,9 @@
 'disabled', this.screen.readonly);
 
 var msg = name + ' / ' + data[1];
-if ((data[1] < data[2]) && (data[2] > this.screen.limit)) {
+if ((data[1] < data[2]) &&
+this.screen.limit !== null &&
+(data[2] > this.screen.limit)) {
 msg += Sao.i18n.gettext(' of ') + data[2];
 }
 this.status_label.text(msg).attr('title', msg);



[tryton-commits] changeset in sao:6.2 Check screen limit is None before comparing

2021-12-23 Thread Cédric Krier
changeset 7965517652ff in sao:6.2
details: https://hg.tryton.org/sao?cmd=changeset=7965517652ff
description:
Check screen limit is None before comparing

issue11015
review389361002
(grafted from 28d16a85ee0d4bb2c7b160e7ee859f7badea216d)
diffstat:

 src/tab.js |  4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diffs (14 lines):

diff -r 822ff8579dde -r 7965517652ff src/tab.js
--- a/src/tab.jsFri Dec 03 21:51:29 2021 +0100
+++ b/src/tab.jsThu Dec 16 22:14:22 2021 +0100
@@ -1483,7 +1483,9 @@
 'disabled', this.screen.readonly);
 
 var msg = name + ' / ' + data[1];
-if ((data[1] < data[2]) && (data[2] > this.screen.limit)) {
+if ((data[1] < data[2]) &&
+this.screen.limit !== null &&
+(data[2] > this.screen.limit)) {
 msg += Sao.i18n.gettext(' of ') + data[2];
 }
 this.status_label.text(msg).attr('title', msg);



[tryton-commits] changeset in modules/stock_quantity_issue:6.0 Use company from u...

2021-12-23 Thread Cédric Krier
changeset c3b4ac571636 in modules/stock_quantity_issue:6.0
details: 
https://hg.tryton.org/modules/stock_quantity_issue?cmd=changeset=c3b4ac571636
description:
Use company from user and filter moves on company

issue11025
review374411002
(grafted from 0d7834d5ffefdc0ed74d22f468cd4c8abdb36378)
diffstat:

 stock.py |  4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diffs (27 lines):

diff -r 6860c1475490 -r c3b4ac571636 stock.py
--- a/stock.py  Fri Nov 05 00:06:27 2021 +0100
+++ b/stock.py  Thu Dec 16 22:21:10 2021 +0100
@@ -195,13 +195,13 @@
 If warehouses is specified it checks the stock only for them.
 """
 pool = Pool()
-Company = pool.get('company.company')
 Date = pool.get('ir.date')
 Location = pool.get('stock.location')
 Move = pool.get('stock.move')
 Product = pool.get('product.product')
 ProductQuantitiesByWarehouse = pool.get(
 'stock.product_quantities_warehouse')
+User = pool.get('res.user')
 
 transaction = Transaction()
 today = Date.today()
@@ -210,7 +210,7 @@
 ('type', '=', 'warehouse'),
 ])
 if company is None:
-company = Company(transaction.context.get('company'))
+company = User(Transaction().user).company
 
 # Do not keep former open issues as they may no more be valid
 opens = cls.search([



[tryton-commits] changeset in modules/stock_quantity_issue:6.2 Use company from u...

2021-12-23 Thread Cédric Krier
changeset 0b95c5a1588d in modules/stock_quantity_issue:6.2
details: 
https://hg.tryton.org/modules/stock_quantity_issue?cmd=changeset=0b95c5a1588d
description:
Use company from user and filter moves on company

issue11025
review374411002
(grafted from 0d7834d5ffefdc0ed74d22f468cd4c8abdb36378)
diffstat:

 stock.py |  4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diffs (27 lines):

diff -r d43bc9d76c49 -r 0b95c5a1588d stock.py
--- a/stock.py  Mon Nov 01 17:15:59 2021 +0100
+++ b/stock.py  Thu Dec 16 22:21:10 2021 +0100
@@ -195,13 +195,13 @@
 If warehouses is specified it checks the stock only for them.
 """
 pool = Pool()
-Company = pool.get('company.company')
 Date = pool.get('ir.date')
 Location = pool.get('stock.location')
 Move = pool.get('stock.move')
 Product = pool.get('product.product')
 ProductQuantitiesByWarehouse = pool.get(
 'stock.product_quantities_warehouse')
+User = pool.get('res.user')
 
 transaction = Transaction()
 today = Date.today()
@@ -210,7 +210,7 @@
 ('type', '=', 'warehouse'),
 ])
 if company is None:
-company = Company(transaction.context.get('company'))
+company = User(Transaction().user).company
 
 # Do not keep former open issues as they may no more be valid
 opens = cls.search([



[tryton-commits] changeset in modules/stock_quantity_early_planning:6.2 Deduce on...

2021-12-23 Thread Cédric Krier
changeset b152a5bce138 in modules/stock_quantity_early_planning:6.2
details: 
https://hg.tryton.org/modules/stock_quantity_early_planning?cmd=changeset=b152a5bce138
description:
Deduce only the minimal future quantity

We can deduce only the quantity that is always available in the future.

issue11013
review381481002
(grafted from df358a8f2ab6e5b40318b61bd2779d70cb7c583f)
diffstat:

 stock.py |  15 +--
 1 files changed, 9 insertions(+), 6 deletions(-)

diffs (33 lines):

diff -r 23eaaadaa7c9 -r b152a5bce138 stock.py
--- a/stock.py  Mon Nov 01 17:15:43 2021 +0100
+++ b/stock.py  Thu Dec 16 22:11:07 2021 +0100
@@ -311,9 +311,12 @@
 ('date', '<=', move.planned_date),
 ],
 order=[('date', 'DESC')]))
-last_product_quantity, = (
-ProductQuantitiesByWarehouse.search(
-[], order=[('date', 'DESC')], limit=1))
+future_product_quantities = (
+ProductQuantitiesByWarehouse.search([
+('date', '>=', move.planned_date),
+]))
+min_future_product_quantity = min(
+p.quantity for p in future_product_quantities)
 earlier_date = move.planned_date
 if product_quantities:
 assert product_quantities[0].date == move.planned_date
@@ -322,10 +325,10 @@
 min_quantity = (
 product_quantities[0].quantity
 + move.internal_quantity)
-if last_product_quantity.quantity > 0:
+if min_future_product_quantity > 0:
 # The remaining quantities can be used
-min_quantity -= last_product_quantity.quantity
-if min_quantity >= 0:
+min_quantity -= min_future_product_quantity
+if min_quantity > 0:
 for product_quantity in product_quantities[1:]:
 if product_quantity.quantity < min_quantity:
 break



[tryton-commits] changeset in modules/stock:5.0 Prevent to compare with None on s...

2021-12-23 Thread Bernat
changeset d82fc633b846 in modules/stock:5.0
details: https://hg.tryton.org/modules/stock?cmd=changeset=d82fc633b846
description:
Prevent to compare with None on searching quantity

issue11047
review387481002
(grafted from 4454b5d28be92099d0faf50c2b825557f5cafa75)
diffstat:

 move.py |  3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diffs (13 lines):

diff -r 92a1efa739ea -r d82fc633b846 move.py
--- a/move.py   Fri Nov 05 00:09:00 2021 +0100
+++ b/move.py   Sat Dec 18 01:38:39 2021 +0100
@@ -142,7 +142,8 @@
 }.get(operator_, lambda v, l: False)
 record_ids = []
 for key, quantity in pbl.items():
-if operator_(quantity, operand):
+if (quantity is not None and operand is not None
+and operator_(quantity, operand)):
 # pbl could return None in some keys
 if key[position] is not None:
 record_ids.append(key[position])



[tryton-commits] changeset in modules/stock:6.0 Prevent to compare with None on s...

2021-12-23 Thread Bernat
changeset 1cb154b545c3 in modules/stock:6.0
details: https://hg.tryton.org/modules/stock?cmd=changeset=1cb154b545c3
description:
Prevent to compare with None on searching quantity

issue11047
review387481002
(grafted from 4454b5d28be92099d0faf50c2b825557f5cafa75)
diffstat:

 move.py |  3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diffs (13 lines):

diff -r 4e317e5c9bd3 -r 1cb154b545c3 move.py
--- a/move.py   Fri Nov 05 00:08:19 2021 +0100
+++ b/move.py   Sat Dec 18 01:38:39 2021 +0100
@@ -158,7 +158,8 @@
 }.get(operator_, lambda v, l: False)
 record_ids = []
 for key, quantity in pbl.items():
-if operator_(quantity, operand):
+if (quantity is not None and operand is not None
+and operator_(quantity, operand)):
 # pbl could return None in some keys
 if key[position] is not None:
 record_ids.append(key[position])



[tryton-commits] changeset in modules/stock:6.2 Prevent to compare with None on s...

2021-12-23 Thread Bernat
changeset c192eb29b7d5 in modules/stock:6.2
details: https://hg.tryton.org/modules/stock?cmd=changeset=c192eb29b7d5
description:
Prevent to compare with None on searching quantity

issue11047
review387481002
(grafted from 4454b5d28be92099d0faf50c2b825557f5cafa75)
diffstat:

 move.py |  3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diffs (13 lines):

diff -r d85418560113 -r c192eb29b7d5 move.py
--- a/move.py   Mon Nov 01 17:08:49 2021 +0100
+++ b/move.py   Sat Dec 18 01:38:39 2021 +0100
@@ -158,7 +158,8 @@
 }.get(operator_, lambda v, l: False)
 record_ids = []
 for key, quantity in pbl.items():
-if operator_(quantity, operand):
+if (quantity is not None and operand is not None
+and operator_(quantity, operand)):
 # pbl could return None in some keys
 if key[position] is not None:
 record_ids.append(key[position])



[tryton-commits] changeset in modules/sale_point:6.2 Add depends on product prope...

2021-12-23 Thread Cédric Krier
changeset ca97898d3005 in modules/sale_point:6.2
details: 
https://hg.tryton.org/modules/sale_point?cmd=changeset=ca97898d3005
description:
Add depends on product properties

issue11023
review354421002
(grafted from 68c7c74d8b768dc24c4e85fcc917fb83cd185eb3)
diffstat:

 product.py |  3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diffs (13 lines):

diff -r 32e9f27c44a4 -r ca97898d3005 product.py
--- a/product.pyMon Nov 01 17:24:45 2021 +0100
+++ b/product.pyThu Dec 16 22:17:49 2021 +0100
@@ -28,7 +28,8 @@
 return pool.get('product.gross_price')
 return super(Template, cls).multivalue_model(field)
 
-@fields.depends('gross_price', 'account_category')
+@fields.depends(
+'gross_price', 'account_category', methods=['customer_taxes_used'])
 def on_change_gross_price(self):
 pool = Pool()
 Tax = pool.get('account.tax')



[tryton-commits] changeset in modules/account_statement_rule:6.2 Fallback to keyw...

2021-12-23 Thread Cédric Krier
changeset 92299b5810d5 in modules/account_statement_rule:6.2
details: 
https://hg.tryton.org/modules/account_statement_rule?cmd=changeset=92299b5810d5
description:
Fallback to keyword search

We do not need to test variable being empty to search by keyword as the
variable may be unbound.

issue11009
review376121002
(grafted from 9f99341984e7847653dc595a267489e2794ef32d)
diffstat:

 account.py |  6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diffs (26 lines):

diff -r e79f8eaf1cee -r 92299b5810d5 account.py
--- a/account.pyMon Nov 01 17:20:23 2021 +0100
+++ b/account.pyThu Dec 16 00:05:10 2021 +0100
@@ -395,11 +395,11 @@
 number, = numbers
 if number.account.owners:
 party = number.account.owners[0]
-if not number:
+else:
 lines = Line.search([
 ('statement.state', 'in', ['validated', 'posted']),
 ('origin.keywords.bank_account', '=',
-keywords['bank_account']),
+bank_account),
 ('party', '!=', None),
 ],
 order=[('date', 'DESC')], limit=1)
@@ -411,7 +411,7 @@
 [('rec_name', 'ilike', keywords['party'])])
 if len(parties) == 1:
 party, = parties
-if not party:
+else:
 lines = Line.search([
 ('statement.state', 'in', ['validated', 'posted']),
 ('origin.keywords.party', '=', keywords['party']),



[tryton-commits] changeset in modules/account_product:6.2 Add depends on product ...

2021-12-23 Thread Cédric Krier
changeset 208bd7a2ae6c in modules/account_product:6.2
details: 
https://hg.tryton.org/modules/account_product?cmd=changeset=208bd7a2ae6c
description:
Add depends on product properties

issue11023
review354421002
(grafted from 9c4d0aef3016c36f91ff159d77e8f9205f71aa61)
diffstat:

 product.py |  8 
 1 files changed, 8 insertions(+), 0 deletions(-)

diffs (58 lines):

diff -r aa529cfe1399 -r 208bd7a2ae6c product.py
--- a/product.pyMon Nov 01 17:09:36 2021 +0100
+++ b/product.pyThu Dec 16 22:17:49 2021 +0100
@@ -47,6 +47,7 @@
 
 def template_property(field_name):
 @property
+@fields.depends('template')
 def prop(self):
 return getattr(self.template, field_name)
 return prop
@@ -343,25 +344,30 @@
 ('accounting', '=', True),
 ])
 
+@fields.depends('account_category')
 def get_account(self, name, **pattern):
 if self.account_category:
 return self.account_category.get_account(name, **pattern)
 
+@fields.depends('account_category')
 def get_taxes(self, name):
 if self.account_category:
 return getattr(self.account_category, name)
 
 @property
+@fields.depends('account_category', methods=['get_account'])
 @account_used('account_expense', 'account_category')
 def account_expense_used(self):
 pass
 
 @property
+@fields.depends('account_category', methods=['get_account'])
 @account_used('account_revenue', 'account_category')
 def account_revenue_used(self):
 pass
 
 @property
+@fields.depends(methods=['get_taxes', 'account_revenue_used'])
 def customer_taxes_used(self):
 taxes = self.get_taxes('customer_taxes_used')
 if taxes is None:
@@ -379,6 +385,7 @@
 return taxes
 
 @property
+@fields.depends(methods=['get_taxes', 'account_expense_used'])
 def supplier_taxes_used(self):
 taxes = self.get_taxes('supplier_taxes_used')
 if taxes is None:
@@ -396,6 +403,7 @@
 return taxes
 
 @property
+@fields.depends(methods=['get_taxes'])
 def supplier_taxes_deductible_rate_used(self):
 return self.get_taxes('supplier_taxes_deductible_rate_used')
 



[tryton-commits] changeset in modules/account:5.0 Compute the periods for type am...

2021-12-23 Thread Cédric Krier
changeset 9d1230fd6b98 in modules/account:5.0
details: https://hg.tryton.org/modules/account?cmd=changeset=9d1230fd6b98
description:
Compute the periods for type amount the same way as general ledger

issue11039
review376171002
(grafted from 491d585d8424f3cdbf05f4e793446e808e5a47dc)
diffstat:

 account.py |  12 
 1 files changed, 8 insertions(+), 4 deletions(-)

diffs (29 lines):

diff -r 39b64965a4cf -r 9d1230fd6b98 account.py
--- a/account.pyThu Dec 16 22:39:44 2021 +0100
+++ b/account.pyThu Dec 16 22:42:53 2021 +0100
@@ -198,6 +198,7 @@
 pool = Pool()
 Account = pool.get('account.account')
 GeneralLedger = pool.get('account.general_ledger.account')
+context = Transaction().context
 
 res = {}
 for type_ in types:
@@ -210,10 +211,13 @@
 for type_ in childs:
 type_sum[type_.id] = Decimal('0.0')
 
-start_period_ids = GeneralLedger.get_period_ids('start_%s' % name)
-end_period_ids = GeneralLedger.get_period_ids('end_%s' % name)
-period_ids = list(
-set(end_period_ids).difference(set(start_period_ids)))
+if context.get('start_period') or context.get('end_period'):
+start_period_ids = GeneralLedger.get_period_ids('start_%s' % name)
+end_period_ids = GeneralLedger.get_period_ids('end_%s' % name)
+period_ids = list(
+set(end_period_ids).difference(set(start_period_ids)))
+else:
+period_ids = None
 
 with Transaction().set_context(periods=period_ids):
 accounts = Account.search([



[tryton-commits] changeset in modules/account:6.0 Compute the periods for type am...

2021-12-23 Thread Cédric Krier
changeset 85e5dcf37bb3 in modules/account:6.0
details: https://hg.tryton.org/modules/account?cmd=changeset=85e5dcf37bb3
description:
Compute the periods for type amount the same way as general ledger

issue11039
review376171002
(grafted from 491d585d8424f3cdbf05f4e793446e808e5a47dc)
diffstat:

 account.py |  12 
 1 files changed, 8 insertions(+), 4 deletions(-)

diffs (29 lines):

diff -r 2e81a78343b3 -r 85e5dcf37bb3 account.py
--- a/account.pyThu Dec 16 22:39:44 2021 +0100
+++ b/account.pyThu Dec 16 22:42:53 2021 +0100
@@ -294,6 +294,7 @@
 pool = Pool()
 Account = pool.get('account.account')
 GeneralLedger = pool.get('account.general_ledger.account')
+context = Transaction().context
 
 res = {}
 for type_ in types:
@@ -306,10 +307,13 @@
 for type_ in childs:
 type_sum[type_.id] = Decimal('0.0')
 
-start_period_ids = GeneralLedger.get_period_ids('start_%s' % name)
-end_period_ids = GeneralLedger.get_period_ids('end_%s' % name)
-period_ids = list(
-set(end_period_ids).difference(set(start_period_ids)))
+if context.get('start_period') or context.get('end_period'):
+start_period_ids = GeneralLedger.get_period_ids('start_%s' % name)
+end_period_ids = GeneralLedger.get_period_ids('end_%s' % name)
+period_ids = list(
+set(end_period_ids).difference(set(start_period_ids)))
+else:
+period_ids = None
 
 with Transaction().set_context(periods=period_ids):
 accounts = Account.search([



[tryton-commits] changeset in modules/account:6.2 Compute the periods for type am...

2021-12-23 Thread Cédric Krier
changeset 0a6428e921c2 in modules/account:6.2
details: https://hg.tryton.org/modules/account?cmd=changeset=0a6428e921c2
description:
Compute the periods for type amount the same way as general ledger

issue11039
review376171002
(grafted from 491d585d8424f3cdbf05f4e793446e808e5a47dc)
diffstat:

 account.py |  12 
 1 files changed, 8 insertions(+), 4 deletions(-)

diffs (29 lines):

diff -r f96c96c62f50 -r 0a6428e921c2 account.py
--- a/account.pyThu Dec 16 22:39:44 2021 +0100
+++ b/account.pyThu Dec 16 22:42:53 2021 +0100
@@ -294,6 +294,7 @@
 pool = Pool()
 Account = pool.get('account.account')
 GeneralLedger = pool.get('account.general_ledger.account')
+context = Transaction().context
 
 res = {}
 for type_ in types:
@@ -306,10 +307,13 @@
 for type_ in childs:
 type_sum[type_.id] = Decimal('0.0')
 
-start_period_ids = GeneralLedger.get_period_ids('start_%s' % name)
-end_period_ids = GeneralLedger.get_period_ids('end_%s' % name)
-period_ids = list(
-set(end_period_ids).difference(set(start_period_ids)))
+if context.get('start_period') or context.get('end_period'):
+start_period_ids = GeneralLedger.get_period_ids('start_%s' % name)
+end_period_ids = GeneralLedger.get_period_ids('end_%s' % name)
+period_ids = list(
+set(end_period_ids).difference(set(start_period_ids)))
+else:
+period_ids = None
 
 with Transaction().set_context(periods=period_ids):
 accounts = Account.search([



[tryton-commits] changeset in modules/account:5.0 Do not reset period or date if ...

2021-12-23 Thread Cédric Krier
changeset 39b64965a4cf in modules/account:5.0
details: https://hg.tryton.org/modules/account?cmd=changeset=39b64965a4cf
description:
Do not reset period or date if changed fill is empty

issue11035
review370401002
(grafted from d471d45ddc0596f28cbefcf4830db73c60b918cd)
diffstat:

 account.py |  20 ++--
 1 files changed, 14 insertions(+), 6 deletions(-)

diffs (51 lines):

diff -r 9a3f7878f6fd -r 39b64965a4cf account.py
--- a/account.pyThu Dec 16 22:35:46 2021 +0100
+++ b/account.pyThu Dec 16 22:39:44 2021 +0100
@@ -1514,7 +1514,7 @@
 ()),
 ],
 states={
-'invisible': (Eval('start_period', 'False')
+'invisible': (Eval('start_period', False)
 | Eval('end_period', False)),
 },
 depends=['to_date', 'start_period', 'end_period'])
@@ -1525,7 +1525,7 @@
 ()),
 ],
 states={
-'invisible': (Eval('start_period', 'False')
+'invisible': (Eval('start_period', False)
 | Eval('end_period', False)),
 },
 depends=['from_date', 'start_period', 'end_period'])
@@ -1574,17 +1574,25 @@
 and self.end_period.fiscalyear != self.fiscalyear):
 self.end_period = None
 
+@fields.depends('start_period')
 def on_change_start_period(self):
-self.from_date = self.to_date = None
+if self.start_period:
+self.from_date = self.to_date = None
 
+@fields.depends('end_period')
 def on_change_end_period(self):
-self.from_date = self.to_date = None
+if self.end_period:
+self.from_date = self.to_date = None
 
+@fields.depends('from_date')
 def on_change_from_date(self):
-self.start_period = self.end_period = None
+if self.from_date:
+self.start_period = self.end_period = None
 
+@fields.depends('to_date')
 def on_change_to_date(self):
-self.start_period = self.end_period = None
+if self.to_date:
+self.start_period = self.end_period = None
 
 
 class GeneralLedgerLine(ModelSQL, ModelView):



[tryton-commits] changeset in modules/account:6.0 Do not reset period or date if ...

2021-12-23 Thread Cédric Krier
changeset 2e81a78343b3 in modules/account:6.0
details: https://hg.tryton.org/modules/account?cmd=changeset=2e81a78343b3
description:
Do not reset period or date if changed fill is empty

issue11035
review370401002
(grafted from d471d45ddc0596f28cbefcf4830db73c60b918cd)
diffstat:

 account.py |  26 +-
 1 files changed, 17 insertions(+), 9 deletions(-)

diffs (54 lines):

diff -r 0fbbe4277280 -r 2e81a78343b3 account.py
--- a/account.pyThu Dec 16 22:37:53 2021 +0100
+++ b/account.pyThu Dec 16 22:39:44 2021 +0100
@@ -1899,7 +1899,7 @@
 ()),
 ],
 states={
-'invisible': (Eval('start_period', 'False')
+'invisible': (Eval('start_period', False)
 | Eval('end_period', False)),
 },
 depends=['to_date', 'start_period', 'end_period'])
@@ -1910,7 +1910,7 @@
 ()),
 ],
 states={
-'invisible': (Eval('start_period', 'False')
+'invisible': (Eval('start_period', False)
 | Eval('end_period', False)),
 },
 depends=['from_date', 'start_period', 'end_period'])
@@ -1970,17 +1970,25 @@
 and self.end_period.fiscalyear != self.fiscalyear):
 self.end_period = None
 
+@fields.depends('start_period')
 def on_change_start_period(self):
-self.from_date = self.to_date = None
-
+if self.start_period:
+self.from_date = self.to_date = None
+
+@fields.depends('end_period')
 def on_change_end_period(self):
-self.from_date = self.to_date = None
-
+if self.end_period:
+self.from_date = self.to_date = None
+
+@fields.depends('from_date')
 def on_change_from_date(self):
-self.start_period = self.end_period = None
-
+if self.from_date:
+self.start_period = self.end_period = None
+
+@fields.depends('to_date')
 def on_change_to_date(self):
-self.start_period = self.end_period = None
+if self.to_date:
+self.start_period = self.end_period = None
 
 
 class GeneralLedgerAccountParty(_GeneralLedgerAccount):



[tryton-commits] changeset in modules/account:6.2 Do not reset period or date if ...

2021-12-23 Thread Cédric Krier
changeset f96c96c62f50 in modules/account:6.2
details: https://hg.tryton.org/modules/account?cmd=changeset=f96c96c62f50
description:
Do not reset period or date if changed fill is empty

issue11035
review370401002
(grafted from d471d45ddc0596f28cbefcf4830db73c60b918cd)
diffstat:

 account.py |  26 +-
 1 files changed, 17 insertions(+), 9 deletions(-)

diffs (54 lines):

diff -r a00817d3e156 -r f96c96c62f50 account.py
--- a/account.pyThu Dec 16 22:35:46 2021 +0100
+++ b/account.pyThu Dec 16 22:39:44 2021 +0100
@@ -1826,7 +1826,7 @@
 ()),
 ],
 states={
-'invisible': (Eval('start_period', 'False')
+'invisible': (Eval('start_period', False)
 | Eval('end_period', False)),
 },
 depends=['to_date', 'start_period', 'end_period'])
@@ -1837,7 +1837,7 @@
 ()),
 ],
 states={
-'invisible': (Eval('start_period', 'False')
+'invisible': (Eval('start_period', False)
 | Eval('end_period', False)),
 },
 depends=['from_date', 'start_period', 'end_period'])
@@ -1897,17 +1897,25 @@
 and self.end_period.fiscalyear != self.fiscalyear):
 self.end_period = None
 
+@fields.depends('start_period')
 def on_change_start_period(self):
-self.from_date = self.to_date = None
-
+if self.start_period:
+self.from_date = self.to_date = None
+
+@fields.depends('end_period')
 def on_change_end_period(self):
-self.from_date = self.to_date = None
-
+if self.end_period:
+self.from_date = self.to_date = None
+
+@fields.depends('from_date')
 def on_change_from_date(self):
-self.start_period = self.end_period = None
-
+if self.from_date:
+self.start_period = self.end_period = None
+
+@fields.depends('to_date')
 def on_change_to_date(self):
-self.start_period = self.end_period = None
+if self.to_date:
+self.start_period = self.end_period = None
 
 
 class GeneralLedgerAccountParty(_GeneralLedgerAccount):



[tryton-commits] changeset in modules/account:6.0 Update parent of type, account,...

2021-12-23 Thread Cédric Krier
changeset 0fbbe4277280 in modules/account:6.0
details: https://hg.tryton.org/modules/account?cmd=changeset=0fbbe4277280
description:
Update parent of type, account, tax and tax code from template

issue11037
review387461002
(grafted from ed7b63a4fdea99ee3c0cf470596b43c6413c07dd)
diffstat:

 account.py|  27 +++
 tax.py|  45 +
 tests/test_account.py |  16 
 3 files changed, 88 insertions(+), 0 deletions(-)

diffs (153 lines):

diff -r c73204d8efed -r 0fbbe4277280 account.py
--- a/account.pyThu Dec 16 22:35:46 2021 +0100
+++ b/account.pyThu Dec 16 22:37:53 2021 +0100
@@ -401,6 +401,26 @@
 if values:
 self.write(*values)
 
+# Update parent
+to_save = []
+childs = [self]
+while childs:
+for child in childs:
+if child.template:
+if not child.template_override:
+if child.template.parent:
+parent = template2type[
+child.template.parent.id]
+else:
+parent = None
+old_parent = (
+child.parent.id if child.parent else None)
+if parent != old_parent:
+child.parent = parent
+to_save.append(child)
+childs = sum((c.childs for c in childs), ())
+self.__class__.save(to_save)
+
 
 class OpenType(Wizard):
 'Open Type'
@@ -1235,6 +1255,13 @@
 for x in child.template.taxes
 if x.id in template2tax])]
 break
+if child.template.parent:
+parent = template2account[child.template.parent.id]
+else:
+parent = None
+old_parent = child.parent.id if child.parent else None
+if parent != old_parent:
+values['parent'] = parent
 if child.template.replaced_by:
 replaced_by = template2account[
 child.template.replaced_by.id]
diff -r c73204d8efed -r 0fbbe4277280 tax.py
--- a/tax.pyThu Dec 16 22:35:46 2021 +0100
+++ b/tax.pyThu Dec 16 22:37:53 2021 +0100
@@ -279,6 +279,29 @@
 if values:
 cls.write(*values)
 
+# Update parent
+to_save = []
+childs = cls.search([
+('company', '=', company_id),
+('parent', '=', None),
+])
+while childs:
+for child in childs:
+if child.template:
+if not child.template_override:
+if child.template.parent:
+parent = template2tax_code[
+child.template.parent.id]
+else:
+parent = None
+old_parent = (
+child.parent.id if child.parent else None)
+if parent != old_parent:
+child.parent = parent
+to_save.append(child)
+childs = sum((c.childs for c in childs), ())
+cls.save(to_save)
+
 
 class TaxCodeLineTemplate(ModelSQL, ModelView):
 "Tax Code Line Template"
@@ -1094,6 +1117,28 @@
 if values:
 cls.write(*values)
 
+# Update parent
+to_save = []
+childs = cls.search([
+('company', '=', company_id),
+('parent', '=', None),
+])
+while childs:
+for child in childs:
+if child.template:
+if not child.template_override:
+if child.template.parent:
+parent = template2tax[child.template.parent.id]
+else:
+parent = None
+old_parent = (
+child.parent.id if child.parent else None)
+if parent != old_parent:
+child.parent = parent
+to_save.append(child)
+childs = sum((c.childs for c in childs), ())
+cls.save(to_save)
+
 
 class _TaxKey(dict):
 
diff -r c73204d8efed -r 0fbbe4277280 tests/test_account.py
--- a/tests/test_account.py Thu Dec 16 22:35:46 2021 +0100
+++ b/tests/test_account.py Thu Dec 16 22:37:53 2021 +0100
@@ -1414,6 +1414,11 @@
 self.assertEqual(type_.name, type_.template.name)
 self.assertEqual(
 type_.statement, type_.template.statement)
+if type_.template.parent:
+

[tryton-commits] changeset in modules/account:5.0 Use the same periods to open ac...

2021-12-23 Thread Cédric Krier
changeset 9a3f7878f6fd in modules/account:5.0
details: https://hg.tryton.org/modules/account?cmd=changeset=9a3f7878f6fd
description:
Use the same periods to open account as in query_get

issue11034
review391231002
(grafted from aeee5ff5c50a0dbe40e8237c41059845df618dee)
diffstat:

 move.py |  24 ++--
 1 files changed, 18 insertions(+), 6 deletions(-)

diffs (45 lines):

diff -r b55d22f22eec -r 9a3f7878f6fd move.py
--- a/move.py   Fri Nov 05 00:21:01 2021 +0100
+++ b/move.py   Thu Dec 16 22:35:46 2021 +0100
@@ -958,7 +958,9 @@
 ('start_date', '<=', date),
 ('end_date', '>=', date),
 ('company', '=', company),
-], limit=1)
+],
+order=[('start_date', 'DESC')],
+limit=1)
 if fiscalyears:
 fiscalyear_id = fiscalyears[0].id
 else:
@@ -1376,15 +1378,25 @@
 open_ = StateAction('account.act_move_line_form')
 
 def do_open_(self, action):
-FiscalYear = Pool().get('account.fiscalyear')
+pool = Pool()
+FiscalYear = pool.get('account.fiscalyear')
+context = Transaction().context
 
-if not Transaction().context.get('fiscalyear'):
+date = context.get('date')
+fiscalyear = context.get('fiscalyear')
+if date:
+fiscalyears = FiscalYear.search([
+('start_date', '<=', date),
+('end_date', '>=', date),
+],
+order=[('start_date', 'DESC')],
+limit=1)
+elif fiscalyear:
+fiscalyears = [FiscalYear(fiscalyear)]
+else:
 fiscalyears = FiscalYear.search([
 ('state', '=', 'open'),
 ])
-else:
-fiscalyears = [FiscalYear(Transaction().context['fiscalyear'])]
-
 periods = [p for f in fiscalyears for p in f.periods]
 
 action['pyson_domain'] = [



[tryton-commits] changeset in modules/account:6.0 Use the same periods to open ac...

2021-12-23 Thread Cédric Krier
changeset c73204d8efed in modules/account:6.0
details: https://hg.tryton.org/modules/account?cmd=changeset=c73204d8efed
description:
Use the same periods to open account as in query_get

issue11034
review391231002
(grafted from aeee5ff5c50a0dbe40e8237c41059845df618dee)
diffstat:

 move.py |  29 +
 1 files changed, 21 insertions(+), 8 deletions(-)

diffs (50 lines):

diff -r 1e6f6acf5c01 -r c73204d8efed move.py
--- a/move.py   Fri Dec 03 21:57:55 2021 +0100
+++ b/move.py   Thu Dec 16 22:35:46 2021 +0100
@@ -1066,7 +1066,9 @@
 ('start_date', '<=', date),
 ('end_date', '>=', date),
 ('company', '=', company),
-], limit=1)
+],
+order=[('start_date', 'DESC')],
+limit=1)
 if fiscalyears:
 fiscalyear_id = fiscalyears[0].id
 else:
@@ -1517,17 +1519,28 @@
 open_ = StateAction('account.act_move_line_form')
 
 def do_open_(self, action):
-FiscalYear = Pool().get('account.fiscalyear')
+pool = Pool()
+FiscalYear = pool.get('account.fiscalyear')
+context = Transaction().context
 
-if not Transaction().context.get('fiscalyear'):
+company_id = self.record.company.id if self.record else -1
+date = context.get('date')
+fiscalyear = context.get('fiscalyear')
+if date:
+fiscalyears = FiscalYear.search([
+('start_date', '<=', date),
+('end_date', '>=', date),
+('company', '=', company_id),
+],
+order=[('start_date', 'DESC')],
+limit=1)
+elif fiscalyear:
+fiscalyears = [FiscalYear(fiscalyear)]
+else:
 fiscalyears = FiscalYear.search([
 ('state', '=', 'open'),
-('company', '=',
-self.record.company.id if self.record else None),
+('company', '=', company_id),
 ])
-else:
-fiscalyears = [FiscalYear(Transaction().context['fiscalyear'])]
-
 periods = [p for f in fiscalyears for p in f.periods]
 
 action['pyson_domain'] = [



[tryton-commits] changeset in modules/account:6.2 Use the same periods to open ac...

2021-12-23 Thread Cédric Krier
changeset a00817d3e156 in modules/account:6.2
details: https://hg.tryton.org/modules/account?cmd=changeset=a00817d3e156
description:
Use the same periods to open account as in query_get

issue11034
review391231002
(grafted from aeee5ff5c50a0dbe40e8237c41059845df618dee)
diffstat:

 move.py |  29 +
 1 files changed, 21 insertions(+), 8 deletions(-)

diffs (50 lines):

diff -r 5caafaaa94ae -r a00817d3e156 move.py
--- a/move.py   Fri Dec 03 21:56:01 2021 +0100
+++ b/move.py   Thu Dec 16 22:35:46 2021 +0100
@@ -1058,7 +1058,9 @@
 ('start_date', '<=', date),
 ('end_date', '>=', date),
 ('company', '=', company),
-], limit=1)
+],
+order=[('start_date', 'DESC')],
+limit=1)
 if fiscalyears:
 fiscalyear_id = fiscalyears[0].id
 else:
@@ -1509,17 +1511,28 @@
 open_ = StateAction('account.act_move_line_form')
 
 def do_open_(self, action):
-FiscalYear = Pool().get('account.fiscalyear')
+pool = Pool()
+FiscalYear = pool.get('account.fiscalyear')
+context = Transaction().context
 
-if not Transaction().context.get('fiscalyear'):
+company_id = self.record.company.id if self.record else -1
+date = context.get('date')
+fiscalyear = context.get('fiscalyear')
+if date:
+fiscalyears = FiscalYear.search([
+('start_date', '<=', date),
+('end_date', '>=', date),
+('company', '=', company_id),
+],
+order=[('start_date', 'DESC')],
+limit=1)
+elif fiscalyear:
+fiscalyears = [FiscalYear(fiscalyear)]
+else:
 fiscalyears = FiscalYear.search([
 ('state', '=', 'open'),
-('company', '=',
-self.record.company.id if self.record else None),
+('company', '=', company_id),
 ])
-else:
-fiscalyears = [FiscalYear(Transaction().context['fiscalyear'])]
-
 periods = [p for f in fiscalyears for p in f.periods]
 
 action['pyson_domain'] = [