Skip to Content
Menu
This question has been flagged
1 Reply
2117 Views

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
Discard
Related Posts Replies Views Activity
0
Mar 15
3088
1
Aug 23
2192
0
Aug 22
1874
1
Mar 23
786
0
Dec 22
1512