1
根據它所依賴的'Start_Date'
,'Cycle_Type'
和'Cycle_val'
我有顯示日期,星期幾如何添加動態字段?
EX
如果
'Start_Date'
= 1月8日的days_to_add
數/ 2017,
'Cycle_Type'
=天
'Cycle_val'
= 3
我768,16具有樹形
日期------------------------------ ----天
01/08/2017 --------------------------星期二
02/08/2017 --------------------------星期三
03/08/2017 -------------- ------------星期四
名class Shift(models.Model):
_name = "working_shift"
_description = "Working Shift"
name = fields.Char(required=True, string ='Name of the shift')
Start_Date = fields.Datetime(string='Start date', required=True, index=True,default=lambda s: fields.Datetime.now())
Cycle_Type=fields.Selection([('week','week'),('day','day')],readonly=False,default='week')
Cycle_val = fields.Integer(required=True, index=True,readonly=False)
Stop_Date = fields.Datetime(string='Stop date', required=True, index=True,default='')
Stop_Date_day = fields.Char(string='Stop date day', required=True, index=True,default='')
Start_Date_day = fields.Char(string='Start date day', required=True, index=True,default='')
@api.onchange('Start_Date', 'Cycle_Type', 'Cycle_val')
def _compute_Stop_Date(self):
for record in self:
days_to_add1=0
days_to_add=0
current_date = fields.Datetime.from_string(record.Start_Date)
day_on=fields.Datetime.from_string(record.Start_Date)
if record.Cycle_Type == 'day':
days_to_add=record.Cycle_val
while days_to_add > 1:
current_date += timedelta(days=1)
days_to_add -= 1
else:
days_to_add1=record.Cycle_val
days_to_add=days_to_add1*7
while days_to_add > 1:
current_date += timedelta(days=1)
days_to_add -= 1
record.Stop_Date=current_date
record.Stop_Date_day=current_date.strftime('%A')
record.Start_Date_day=day_on.strftime('%A')
編輯
<notebook>
<page name="working" string="working time">
<group>
<field name="Date_range" mode="tree,kanban" >
<tree string="workings">
<field name="date"/>
<field name="day"/>
</tree>
</field>
</group>
</page>
</notebook>
感謝您的答案,但它仍然只顯示一個,請參閱編輯plz – Borealis
我更新了我的答案。覈實。 –
它顯示日期和日期,但現在不顯示最後一條記錄 – Borealis