Skip to Content
Menu
This question has been flagged
2807 Views

I try to write a copy function to copy data from table to same table.

hre_formmst_id is Many2one field. hre_formdtl_ids is One2many field.

Use a button to call this function.

def formmst_copy_func(self):
_logger.info('=== formmst_copy_func start ===')
for record in self:
formbas_obj = self.env['hre.formmst']
defaults = {
'form_no': record.form_no,
'hre_orgbas_id': record.hre_orgbas_id.id if record.hre_orgbas_id else False,
'form_name': record.hre_formmst_id.form_name,
'form_type': record.hre_formmst_id.form_type,
'calculate_type': record.hre_formmst_id.calculate_type,
'total_score': record.hre_formmst_id.total_score,
'hre_formdtl_ids': record.hre_formmst_id.hre_formdtl_ids,
}
formbas_obj.create(defaults)
_logger.info('=== formmst_copy_func end ===')
<record id="form_hre_formbas_copy_wizard" model="ir.ui.view">
<field name="name"<form.hre.formbas.copy.wizard</field>
<field name="model"<hre.formbas.copy.wizard</field>
<field name="arch" type="xml">
<form>
<group col="4">
<field name="hre_formmst_id"/>
<newline/>
<field name="form_no"/>
<field name="hre_orgbas_id"/>
</group>
<footer>
<button string="Copy" name="formmst_copy_func" type="object" class="oe_highlight"/>
or
<button string="Cancel" special="cancel" type="object" class="oe_link"/>
</footer>
</form>
</field>
</record>

The function can copy data successfully.
But the hre_formdtl_ids in the original data disappeared.
How can I fix the function? Please give me some suggestions. Thanks!

Avatar
Discard
Related Posts Replies Views Activity
5
Oct 24
28439
1
Jul 23
4380
2
Jul 22
9107
2
Oct 21
1932
0
Aug 21
1172