Hello,
I'm getting a singleton error in if-else condition and would like to add for loop to run code smoothly. The error is arising at
'partner_id': rec.partner_ids.id,
in which partner_ids is many2many. The action code is as below
def action_create_purchase_order(self):
"""create purchase order and internal transfer"""
for rec in self.requisition_order_ids:
if rec.requisition_type == 'internal_transfer':
self.env['stock.picking'].create({
'location_id': self.source_location_id.id,
'location_dest_id': self.destination_location_id.id,
'picking_type_id': self.internal_picking_id.id,
'requisition_order': self.name,
'move_ids_without_package': [(0, 0, {
'name': rec.product_id.name,
'product_id': rec.product_id.id,
'product_uom': rec.product_id.uom_id,
'product_uom_qty': rec.quantity,
'location_id': self.source_location_id.id,
'location_dest_id': self.destination_location_id.id,
})]
})
else:
self.env['purchase.order'].create({
'partner_id': rec.partner_ids.id,
'requisition_order': self.name,
'project_requisition_name': self.project_requisition_name_id.name,
'job_number': self.job_num,
"order_line": [(0, 0, {
'product_id': rec.product_id.id,
'product_qty': rec.quantity,
'name': rec.description,
})]})
self.write({'state': 'purchase_order_created'})
Thank you in advance.