I need to save a timestamp to some records in the current many2many field. I am not sure how to select only some of the records belonging to an order to achieve this. Normally in the regular tree view there are checkboxes for selecting records on the first column, but on a form view, I haven't been able to create those checkboxes. Here is a simplified version of my code:
class Order(models.Model):
_name = 'my.order'
items = fields.One2many('my.items', inverse_name='order', ondelete='set null')
date_helper = fields.Datetime(store=False) # Not sure if store=False works but I don't really need to store this here.def save_item_dates(self):
for i in self.selected_items: # Don't know how to get selected items
i.arrival = self.date_helperclass Item(models.Model):
_name = 'my.item'
order = fields.Many2one.('my.order')
arrival = fields.Datetime()##### Order's XML form<form>
<sheet>
<header>
<button string="Save Dates" type="object" name="save_item_dates" class="oe_highlight" icon="fa-check-square-o"/>
</header>
<group>
<field name="date_helper"/>
<field name="items" widget="many2many" domain="[('order', '=', None)]"/>
</group>
</sheet>
</form>
I want to save the arrival date only for items that have already arrived.
What is the best way to apply the function to some items only?
I know I could try using boolean fields and mark them on edit mode inside the form while triggering onchange. But that solution requires 2 clicks per item for the user and is not very intuitive, it also doesn't come with a select all button, although I could make one.