Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
1 Rispondi
3168 Visualizzazioni

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
Abbandona
Post correlati Risposte Visualizzazioni Attività
0
mar 15
3840
1
mag 25
4089
0
ago 22
2783
1
mar 23
2148
0
dic 22
2798