From e1b80cc05c8fdaef7f34fae7537524e4048b324c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Wed, 18 Dec 2019 21:41:21 +0100 Subject: [PATCH] Use multiselection for days issue8894 review264881004 --- CHANGELOG | 2 ++ purchase.py | 25 ++++++++----------- purchase.xml | 22 ---------------- view/product_supplier_form.xml | 4 +-- view/product_supplier_weekday_form.xml | 10 -------- view/product_supplier_weekday_tree.xml | 7 ------ ...product_supplier_weekday_tree_editable.xml | 7 ------ 7 files changed, 14 insertions(+), 63 deletions(-) delete mode 100644 view/product_supplier_weekday_form.xml delete mode 100644 view/product_supplier_weekday_tree.xml delete mode 100644 view/product_supplier_weekday_tree_editable.xml diff --git a/CHANGELOG b/CHANGELOG index 2ad5af8786..e83255f957 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,5 @@ +* Use multiselection for days + Version 5.4.0 - 2019-11-04 * Bug fixes (see mercurial logs for details) diff --git a/purchase.py b/purchase.py index 29d8e3146b..abbf245b03 100644 --- a/purchase.py +++ b/purchase.py @@ -1,7 +1,7 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. import datetime -from trytond.model import ModelView, ModelSQL, fields +from trytond.model import ModelSQL, fields from trytond.pool import PoolMeta, Pool from trytond.transaction import Transaction @@ -10,16 +10,16 @@ __all__ = ['ProductSupplier', 'ProductSupplierDay'] class ProductSupplier(metaclass=PoolMeta): __name__ = 'purchase.product_supplier' - weekdays = fields.One2Many('purchase.product_supplier.day', - 'product_supplier', 'Week Days') + weekdays = fields.Many2Many( + 'purchase.product_supplier.day', 'product_supplier', 'day', + "Week Days") def compute_supply_date(self, date=None): date = super(ProductSupplier, self).compute_supply_date(date=date) earlier_date = None if date != datetime.date.max: for weekday in self.weekdays: - weekday = weekday.day.index - diff = weekday - date.weekday() + diff = weekday.index - date.weekday() if diff < 0: diff += 7 new_date = date + datetime.timedelta(diff) @@ -32,8 +32,7 @@ class ProductSupplier(metaclass=PoolMeta): def compute_purchase_date(self, date): later_date = None for weekday in self.weekdays: - weekday = weekday.day.index - diff = (date.weekday() - weekday) % 7 + diff = (date.weekday() - weekday.index) % 7 new_date = date - datetime.timedelta(diff) if later_date and later_date >= new_date: continue @@ -43,11 +42,12 @@ class ProductSupplier(metaclass=PoolMeta): return super(ProductSupplier, self).compute_purchase_date(date) -class ProductSupplierDay(ModelSQL, ModelView): +class ProductSupplierDay(ModelSQL): 'Product Supplier Day' __name__ = 'purchase.product_supplier.day' - product_supplier = fields.Many2One('purchase.product_supplier', 'Supplier', - required=True, ondelete='CASCADE') + product_supplier = fields.Many2One( + 'purchase.product_supplier', 'Supplier', + required=True, ondelete='CASCADE', select=True) day = fields.Many2One('ir.calendar.day', "Day", required=True) @classmethod @@ -71,8 +71,3 @@ class ProductSupplierDay(ModelSQL, ModelView): [table.day], [day_id], where=table.weekday == str(index))) table_h.drop_column('weekday') - - @classmethod - def __setup__(cls): - super(ProductSupplierDay, cls).__setup__() - cls._order.insert(0, ('day', 'ASC')) diff --git a/purchase.xml b/purchase.xml index 9255eaf36e..542be0be3c 100644 --- a/purchase.xml +++ b/purchase.xml @@ -8,27 +8,5 @@ this repository contains the full copyright notices and license terms. --> product_supplier_form - - - purchase.product_supplier.day - form - product_supplier_weekday_form - - - - purchase.product_supplier.day - tree - - product_supplier_weekday_tree - - - - purchase.product_supplier.day - tree - - product_supplier_weekday_tree_editable - - diff --git a/view/product_supplier_form.xml b/view/product_supplier_form.xml index 7e86360347..111fdc684f 100644 --- a/view/product_supplier_form.xml +++ b/view/product_supplier_form.xml @@ -3,7 +3,7 @@ this repository contains the full copyright notices and license terms. --> - + diff --git a/view/product_supplier_weekday_form.xml b/view/product_supplier_weekday_form.xml deleted file mode 100644 index 5918074ee3..0000000000 --- a/view/product_supplier_weekday_form.xml +++ /dev/null @@ -1,10 +0,0 @@ - - -
-