Odoo:Odoo 12中等效的OpenERP7 _prepare_purchase_order_line方法

时间:2019-09-12 13:20:06

标签: odoo openerp-7 odoo-12


我正在将旧模块从OpenERP 7迁移到Odoo12。我陷入了这种称为_prepare_purchase_order_line的方法,您可以在模型purchase.requisition中找到它。
这是它的代码:

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

我想知道Odoo 12中该方法的等效功能。
你能帮我吗?

1 个答案:

答案 0 :(得分:1)

我可以看到这种方法在odoo 12中存在相同的名称,但是在purchase.requisition.line模型中。

    @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 []
        }