.py Code
from flectra import models, fields,api,_fromdatetimeimportdatetime, date, timedeltafrom flectra.tools import DEFAULT_SERVER_DATE_FORMAT# from flectra.date import date
classweekreports(models.Model):_name = 'week.task'_description ='Generate Week Base Reports'name=fields.Char(string='Name')total_days = fields.Integer(string="Total Days",store=True)active = fields.Boolean(default=True)number_of_days = fields.One2many('number.of.days','week_task',string='Number of Days')
classNumberOfDays(models.Model):_name = 'number.of.days'week_task = fields.Many2one('week.task', string='Week Tasks')no_of_days = fields.Integer(string="Number of Days")st_date = fields.Date(string='Start Date')end_date = fields.Date(string='End Date')@api.depends('st_date','end_date')@api.onchange('st_date','end_date')defchange_numbber(self):forrecinself:days = 0ifrec.st_date andrec.end_date:duration = datetime.strptime(str(rec.end_date), DEFAULT_SERVER_DATE_FORMAT) - datetime.strptime(str(rec.st_date),DEFAULT_SERVER_DATE_FORMAT)rec.no_of_days = duration.days
.xml Code
<flectra><data><recordid="app_task_id"model="ir.actions.act_window"><fieldname="name">Weeksfield><fieldname="res_model">week.taskfield><fieldname="view_mode">tree,formfield>record><recordid="week_tree"model="ir.ui.view"><fieldname="name">week.task.treefield><fieldname="model">week.taskfield><fieldname="arch"type="xml"><treestring="Weeks"><fieldname='name'/><fieldname="total_days"/><fieldname="active"/>tree>field>record>
<recordid='week_task_form_view'model='ir.ui.view'><fieldname='name'>week.task.form.viewfield><fieldname='model'>week.taskfield><fieldname='arch'type='xml'><form><header>header><sheet><group><group><fieldname='name'/>group><group><fieldname='total_days'/>group>group><notebook><pagestring="NO Of Days"><fieldname="number_of_days"><treestring="No of Days"editable="bottom"><fieldname="st_date"/><fieldname="end_date"/><fieldname="no_of_days"/>tree>field>page>notebook>sheet>form>field>record>
<menuitemid="days_task"name="Days"action="app_task_id"sequence="1"groups="base.group_user"/>data>flectra>