Add ir.calendar for month and day
This allows to replace time_locale and use the translation infrastructure instead. So it can be customized using the translation override or derivative languages. This provides also a standard base to modules that needs calendar month and day. issue7815 review56451002
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
* Use ir.calendar.day
|
||||
|
||||
Version 5.0.0 - 2018-10-01
|
||||
* Bug fixes (see mercurial logs for details)
|
||||
* Remove support for Python 2.7
|
||||
|
||||
+30
-19
@@ -2,7 +2,8 @@
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
import datetime
|
||||
from trytond.model import ModelView, ModelSQL, fields
|
||||
from trytond.pool import PoolMeta
|
||||
from trytond.pool import PoolMeta, Pool
|
||||
from trytond.transaction import Transaction
|
||||
|
||||
__all__ = ['ProductSupplier', 'ProductSupplierDay']
|
||||
|
||||
@@ -16,8 +17,8 @@ class ProductSupplier(metaclass=PoolMeta):
|
||||
date = super(ProductSupplier, self).compute_supply_date(date=date)
|
||||
earlier_date = None
|
||||
if date != datetime.date.max:
|
||||
for day in self.weekdays:
|
||||
weekday = int(day.weekday)
|
||||
for weekday in self.weekdays:
|
||||
weekday = weekday.day.index
|
||||
diff = weekday - date.weekday()
|
||||
if diff < 0:
|
||||
diff += 7
|
||||
@@ -30,8 +31,8 @@ class ProductSupplier(metaclass=PoolMeta):
|
||||
|
||||
def compute_purchase_date(self, date):
|
||||
later_date = None
|
||||
for day in self.weekdays:
|
||||
weekday = int(day.weekday)
|
||||
for weekday in self.weekdays:
|
||||
weekday = weekday.day.index
|
||||
diff = (date.weekday() - weekday) % 7
|
||||
new_date = date - datetime.timedelta(diff)
|
||||
if later_date and later_date >= new_date:
|
||||
@@ -47,21 +48,31 @@ class ProductSupplierDay(ModelSQL, ModelView):
|
||||
__name__ = 'purchase.product_supplier.day'
|
||||
product_supplier = fields.Many2One('purchase.product_supplier', 'Supplier',
|
||||
required=True, ondelete='CASCADE')
|
||||
weekday = fields.Selection([
|
||||
('0', 'Monday'),
|
||||
('1', 'Tuesday'),
|
||||
('2', 'Wednesday'),
|
||||
('3', 'Thursday'),
|
||||
('4', 'Friday'),
|
||||
('5', 'Saturday'),
|
||||
('6', 'Sunday'),
|
||||
], 'Week Day', required=True, sort=False)
|
||||
day = fields.Many2One('ir.calendar.day', "Day", required=True)
|
||||
|
||||
@classmethod
|
||||
def __register__(cls, module_name):
|
||||
pool = Pool()
|
||||
Day = pool.get('ir.calendar.day')
|
||||
day = Day.__table__()
|
||||
transaction = Transaction()
|
||||
table = cls.__table__()
|
||||
|
||||
super().__register__(module_name)
|
||||
table_h = cls.__table_handler__(module_name)
|
||||
|
||||
# Migration from 5.0: replace weekday by day
|
||||
if table_h.column_exist('weekday'):
|
||||
cursor = transaction.connection.cursor()
|
||||
update = transaction.connection.cursor()
|
||||
cursor.execute(*day.select([day.id, day.index]))
|
||||
for day_id, index in cursor:
|
||||
update.execute(*table.update(
|
||||
[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, ('weekday', 'ASC'))
|
||||
|
||||
@staticmethod
|
||||
def default_weekday():
|
||||
return '0'
|
||||
cls._order.insert(0, ('day', 'ASC'))
|
||||
|
||||
@@ -104,6 +104,7 @@ class StockSupplyDayTestCase(ModuleTestCase):
|
||||
Account = pool.get('account.account')
|
||||
ProductSupplier = pool.get('purchase.product_supplier')
|
||||
ProductSupplierDay = pool.get('purchase.product_supplier.day')
|
||||
Day = pool.get('ir.calendar.day')
|
||||
|
||||
uom_category, = UomCategory.create([{'name': 'Test'}])
|
||||
uom, = Uom.create([{
|
||||
@@ -144,9 +145,10 @@ class StockSupplyDayTestCase(ModuleTestCase):
|
||||
'lead_time': lead_time,
|
||||
}])
|
||||
if weekday is not None:
|
||||
day, = Day.search([('index', '=', weekday)])
|
||||
ProductSupplierDay.create([{
|
||||
'product_supplier': product_supplier.id,
|
||||
'weekday': str(weekday),
|
||||
'day': day.id,
|
||||
}])
|
||||
return product_supplier
|
||||
|
||||
|
||||
@@ -5,6 +5,6 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<label name="product_supplier"/>
|
||||
<field name="product_supplier"/>
|
||||
<newline/>
|
||||
<label name="weekday"/>
|
||||
<field name="weekday"/>
|
||||
<label name="day"/>
|
||||
<field name="day" widget="selection"/>
|
||||
</form>
|
||||
|
||||
@@ -3,5 +3,5 @@
|
||||
this repository contains the full copyright notices and license terms. -->
|
||||
<tree>
|
||||
<field name="product_supplier"/>
|
||||
<field name="weekday"/>
|
||||
<field name="day" widget="selection"/>
|
||||
</tree>
|
||||
|
||||
@@ -3,5 +3,5 @@
|
||||
this repository contains the full copyright notices and license terms. -->
|
||||
<tree editable="bottom">
|
||||
<field name="product_supplier"/>
|
||||
<field name="weekday" expand="1"/>
|
||||
<field name="day" expand="1" widget="selection"/>
|
||||
</tree>
|
||||
|
||||
Reference in New Issue
Block a user