I need it when adding one2many
records in form not in tree.
When you click save & new save the fields and keep some fields not to be cleared to add a new record.
Make one2many
modal remember fields
remember [analaytic_account_id,product_id,vendor_id]
class MkVoucher(models.Model):
_name = 'mk.voucher'
voucher_line_ids = fields.One2many('mk.voucher.line', 'voucher_id', string='Voucher Lines', copy=True)
class MkVoucherLine(models.Model):
_name = 'mk.voucher.line'
voucher_id = fields.Many2one('mk.voucher' , string='Voucher')
product_id = fields.Many2one('product.product', string='Product',required=True)
analytic_account_id = fields.Many2one('account.analytic.account', string='Analytic Account',required=True)
partner_id = fields.Many2one('res.partner', string='Vendor', required=True,)
product_id = fields.Many2one('product.product', string='Product', required=True, default=lambda self: self._default_product_id())
@api.model
def _default_product_id(self):
latest_line = self.env['mk.voucher.line'].search([], order="id desc", limit=1)
return latest_line.product_id.id if latest_line else False
New contributor
OakarminIron is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.