How to get duplicate in One2many form, ex, A is a parent form, it has one one2many field, this one2many field has 5 fields, like name, age, dept, supervisor, shift. In this case shift and supervisor will entered by the user click on the Add New Items button in the first form, this two values needed for next 4 records while clicking the button Save&New, How to do that.
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Accounting
- Inventory
- PoS
- Project management
- MRP
This question has been flagged
I added more clear for reviews of Prakash. To one2many autoloading after clicking on the button, you add option for the field options="{'reload_on_button': true}".
Example:
<field name="x_design_content_building" options="{'reload_on_button': true}" string="Building data">
<tree>
<field name="x_bulding_name" string="Building name" />
<field name="x_is_multifloor_building" string="Multifloor" />
<button name="duplicate" type="object" groups="base.group_sale_salesman" string="Duplicate"/>
</tree>
</field>
Create a button in the one2many form and override the copy method.
Example In one2many form,
Xml File
<button name="duplicate" type="object" string="Duplicate Line"/>
Python File
_name = 'table.name.line'
def duplicate(self, cr, uid, ids, context=None):
res = self.pool.get('table.name.line').copy(cr, uid, ids[0], default=None, context=context)
return res
This works only if the parent object has been saved (and thus child objects as well). The children don't have an ID before they have been saved, and in one2many relationship they are saved only when the parent is saved.