I have a child class as below:
class ProjectPeriod(ModelSQL, ModelView):
"Project Period"
__name__ = "afx.project.period"
_rec_name = 'po_no'
update_mode = fields.Selection([
(None, 'None'),
('MOVE_PERIOD', 'Move Period'),
('UPDATE_DATE', 'Update Date')
], 'Update Mode', sort=False,
states={
'invisible': Eval('id', -1) < 0,
}
)
project = fields.Many2One('afx.project', "Project", required=True, ondelete='CASCADE')
proj_phase = fields.Char("Project Phase", required=False, states={
'readonly': True
})
start_date = fields.Date("Period Start Date", required=True,
states={
'readonly': Eval('is_running', False) == True,
}
)
end_date = fields.Date("Period End Date", required=True,
states={
'readonly': Eval('is_running', False) == True,
}
)
chargeable = fields.Boolean("Chargeable",
states={
'readonly': Eval('is_running', False) == True,
}
)
sow_no = fields.Char("SOW Number",
states={
'invisible': Eval('chargeable', False) == False,
'readonly': Eval('is_phase_different', False) == True,
}
)
po_no = fields.Char("PO Number",
states={
'invisible': Eval('chargeable', False) == False,
'readonly': Eval('is_phase_different', False) == True,
}
)
quot_no = fields.Char("Quotation Number",
states={
'invisible': Eval('chargeable', False) == False,
'readonly': Eval('is_phase_different', False) == True,
}
)
loa = fields.Char("LOA",
states={
'invisible': Eval('chargeable', False) == False,
'readonly': Eval('is_phase_different', False) == True,
}
)
remark = fields.Char('Remark', states={
'readonly': Eval('is_phase_different', False) == True,
})
commitment = fields.Integer('Commitment (Days)',
states={
'required': Eval('is_support', False) == True,
'readonly': Or(
Eval('is_running', False) == True,
Eval('is_phase_different', False) == True,
)
}
)
uuid = fields.Char('UUID', states= {
'invisible': True,
'readonly': True,
})
And inside a parent class I have One2Many of the above object under planning_periods_on_details_pg field as below:
planning_periods_on_details_pg = fields.One2Many('afx.project.period', 'project', "Planned Periods",
required=False,
filter=[('proj_phase', '=', 'PLANNING')],
order=[('start_date', 'asc')],
states={
'readonly': Eval('id', -1) < 0,
'invisible': Or(
Eval('proj_type_view') == 'SUPPORT-SP',
Eval('proj_type_view') == 'SUPPORT-MP',
),
}, depends=['id','proj_type_view']
)
During updates and parent class execute def write method, and I received data something like below:
[['add', [506, 507]], ['write', [506], {'end_date': datetime.date(2026, 9, 10), 'start_date': datetime.date(2025, 10, 13)}, [507], {'end_date': datetime.date(2026, 7, 28), 'update_mode': 'UPDATE_DATE'}]]
I tried to parse it below:
@classmethod
def write(cls, records, values, *args):
if 'planning_periods_on_details_pg' in values:
cmd = values['planning_periods_on_details_pg'][0][0]
logger.info(f'>>>>>>>>>>>>>>>>> CMD: {cmd}')
if cmd == 'add':
ids = values['planning_periods_on_details_pg'][0][1]
logger.info(f'>>>>>>>>>>>>>>>>> IDS: {ids}')
upd_info = values['planning_periods_on_details_pg'][1]
upd_info = upd_info[1:]
logger.info(f'>>>>>>>>>>>>>>>>> OPT: {upd_info}')
n = len(upd_info)
logger.info(f'>>>>>>>>>>>>>>>>> UPD INFO LENGTH: {n}')
operation = values['planning_periods_on_details_pg'][1][0]
logger.info(f'>>>>>>>>>>>>>>>>> OPT: {operation}')
if operation == 'write':
for i in range(n):
info = upd_info[i]
logger.info(f'>>>>>>>>>>>>>>>>> INFO: {info}')
I know I am doing a wrong thing in-order to parse the received data.
Anybody knows how to parse the data in python ORM way? any link to a sample code?
Bromo