Use multiselection for days

issue8894
review264881004
This commit is contained in:
Cédric Krier committed 2019-12-18 21:41:21 +01:00
1 parent e8a0e12859
commit e1b80cc05c
7 files changed
+14 -63

No files matched your search

+2
View File
@@ -1,3 +1,5 @@
* Use multiselection for days
Version 5.4.0 - 2019-11-04
* Bug fixes (see mercurial logs for details)
+10 -15
View File
@@ -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'))
-22
View File
@@ -8,27 +8,5 @@ this repository contains the full copyright notices and license terms. -->
<field name="inherit" ref="purchase.product_supplier_view_form"/>
<field name="name">product_supplier_form</field>
</record>
<record model="ir.ui.view" id="product_supplier_weekdayview_form">
<field name="model">purchase.product_supplier.day</field>
<field name="type">form</field>
<field name="name">product_supplier_weekday_form</field>
</record>
<record model="ir.ui.view" id="product_supplier_weekdayview_tree">
<field name="model">purchase.product_supplier.day</field>
<field name="type">tree</field>
<field name="priority" eval="10"/>
<field name="name">product_supplier_weekday_tree</field>
</record>
<record model="ir.ui.view"
id="product_supplier_weekdayview_tree_editable">
<field name="model">purchase.product_supplier.day</field>
<field name="type">tree</field>
<field name="priority" eval="20"/>
<field name="name">product_supplier_weekday_tree_editable</field>
</record>
</data>
</tryton>
+2 -2
View File
@@ -3,7 +3,7 @@
this repository contains the full copyright notices and license terms. -->
<data>
<xpath expr="/form/field[@name='lead_time']" position="after">
<field name="weekdays" colspan="4"
view_ids="stock_supply_day.product_supplier_weekdayview_tree_editable"/>
<label name="weekdays"/>
<field name="weekdays" widget="multiselection" yexpand="0"/>
</xpath>
</data>
-10
View File
@@ -1,10 +0,0 @@
<?xml version="1.0"?>
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
this repository contains the full copyright notices and license terms. -->
<form>
<label name="product_supplier"/>
<field name="product_supplier"/>
<newline/>
<label name="day"/>
<field name="day" widget="selection"/>
</form>
-7
View File
@@ -1,7 +0,0 @@
<?xml version="1.0"?>
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
this repository contains the full copyright notices and license terms. -->
<tree>
<field name="product_supplier"/>
<field name="day" widget="selection"/>
</tree>
@@ -1,7 +0,0 @@
<?xml version="1.0"?>
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
this repository contains the full copyright notices and license terms. -->
<tree editable="bottom">
<field name="product_supplier"/>
<field name="day" expand="1" widget="selection"/>
</tree>