I am currently using the native module of odoo [Sales] -sales orders and I want to pass the registration of a One2many field at the moment of pressing the button that redirects me to another new formula that I have created and has a field One2Mnay.
example: this is the native module of odo where I am registering my sales orders:
I have created a new botton that is red says [registrar cotizacion] , called method: [open_budget] which allows to open a new form that I created and has a field one2many :
My models :
Models of new form :
class BudgetTwo(models.Model):
_name = 'budget.two'
name = fields.Char(string ='Nombre', copy=False, index=True ,default ="Nuevo")
partner_id =fields.Many2one('res.partner' ,string ='Cliente', copy=False, index=True,required=True)
deliver_date = fields.Date(string ='Fecha de Entrega')
expiration_date = fields.Date(string ='Fecha de expiración')
pay_place =fields.Many2one('account.payment.term' ,string='Plazo de Pago')
order_line = fields.One2many('budget.table','budget_id' ,string = 'Pedidos' )
total = fields.Float(string = 'Total:' ,compute="_total")
btn_d = fields.Boolean(default = False)
Inheritance of the odoo's own module:
class InheritOrder(models.Model):
_inherit = 'sale.order'
@api.multi
def open_budget(self):
if self.order_line:
for element in self.order_line:
data = element.product_id.id
else:print('none')
print(data)
return {
'name': ('Payments'),
'view_type': 'form',
'view_mode': 'form',
'res_model': 'budget.two',
'view_id': False,
'type': 'ir.actions.act_window',
'context': {
'default_partner_id': self.partner_id.id,
'default_order_line.product_id': data,
'default_order_line.product_id': data,
},
}
the native module of odoo has a field One2many that are the orders, when I press the new botton loogre redirect to the new form that I created and created a dictionary which has a key called context I can pass the records that I have in the fields but the record that I have in the one2many values are not passed.
Finally :
'context': {
'default_partner_id': self.partner_id.id,
'default_order_line.product_id': data,
'default_order_line.product_id': data,
},
desauld_pernert_id if the record passes but default_order_line.product_id does not pass the record that is the on2many, as you can see: