odooopenerp-7odoo-12

Odoo : OpenERP7 _prepare_purchase_order_line method equivalent in Odoo 12



I'm working on migrating an old module from OpenERP 7 to Odoo 12. I'm stuck in this method called _prepare_purchase_order_line, you can find it in model purchase.requisition.
Here is its code :

def make_purchase_order(self, cr, uid, ids, partner_id, context=None):
    """
    Create New RFQ for Supplier
    """
    context = dict(context or {})
    assert partner_id, 'Supplier should be specified'
    purchase_order = self.pool.get('purchase.order')
    purchase_order_line = self.pool.get('purchase.order.line')
    res_partner = self.pool.get('res.partner')
    supplier = res_partner.browse(cr, uid, partner_id, context=context)
    res = {}
    for requisition in self.browse(cr, uid, ids, context=context):
        if not requisition.multiple_rfq_per_supplier and supplier.id in filter(lambda x: x, [rfq.state != 'cancel' and rfq.partner_id.id or None for rfq in requisition.purchase_ids]):
            raise osv.except_osv(_('Warning!'), _('You have already one %s purchase order for this partner, you must cancel this purchase order to create a new quotation.') % rfq.state)
        context.update({'mail_create_nolog': True})
        purchase_id = purchase_order.create(cr, uid, self._prepare_purchase_order(cr, uid, requisition, supplier, context=context), context=context)
        purchase_order.message_post(cr, uid, [purchase_id], body=_("RFQ created"), context=context)
        res[requisition.id] = purchase_id
        for line in requisition.line_ids:
            purchase_order_line.create(cr, uid, self._prepare_purchase_order_line(cr, uid, requisition, line, purchase_id, supplier, context=context), context=context)
    return res

I want to know what is the equivalent of this method in Odoo 12.
Can you help me?


Solution

  • I can see this method exist with the same name in odoo 12 but it is in purchase.requisition.line model.

        @api.multi
        def _prepare_purchase_order_line(self, name, product_qty=0.0, price_unit=0.0, taxes_ids=False):
            self.ensure_one()
            requisition = self.requisition_id
            if requisition.schedule_date:
                date_planned = datetime.combine(requisition.schedule_date, time.min)
            else:
                date_planned = datetime.now()
            return {
                'name': name,
                'product_id': self.product_id.id,
                'product_uom': self.product_id.uom_po_id.id,
                'product_qty': product_qty,
                'price_unit': price_unit,
                'taxes_id': [(6, 0, taxes_ids)],
                'date_planned': date_planned,
                'account_analytic_id': self.account_analytic_id.id,
                'analytic_tag_ids': self.analytic_tag_ids.ids,
                'move_dest_ids': self.move_dest_id and [(4, self.move_dest_id.id)] or []
            }