Ir al contenido
Menú
Se marcó esta pregunta
1 Responder
3083 Vistas

In approvals app, when I create a new RFQ (new request), I inherited the view and added smart button to it in addition to a many2one field(purchase_agreement_id) taken from the model purchase.requisition in order to take the purchase id and fill the one2many field below it. What I want to do, is when pressing on the smart button, it will be responsible for taking me from the current form to another form and sending along it the products filled in my one2many field. I have already made a code that is responsible for filling the one2many field when changing the purchase_agreement_id (many2one field) but I still need to fill them in the next form upon button click. Here  is my code: 


from odoo import models,api,fields
from odoo.exceptions import ValidationError
class Approval(models.Model):
_inherit = "approval.request"
purchase_agreement_id=fields.Many2one('purchase.requisition', string='Purchase Agreement Id')

@api.onchange('purchase_agreement_id')
def purchase_agreement(self):
lines = []
for rec in self:
for line in rec.purchase_agreement_id.line_ids:
lines.append([0,0,{
'product_id': line.product_id.id,'description':line.product_description_variants,'quantity':line.product_qty
}])
self.product_line_ids=[(6, 0, [])]
self.write({'product_line_ids' : lines})

The above code is only responsible for filling the one2many field in the approval.request model, I have tried so many codes to move the products to the next form but I am stuck. Any help would be appreciated. Thanks

Avatar
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
0
mar 15
3783
1
may 25
3911
0
ago 22
2698
1
mar 23
2044
0
dic 22
2704