如何在销售订单odoo 10中覆盖创建方法以添加po RFQ

时间:2018-03-08 12:03:57

标签: odoo purchase-order

我尝试在销售订单中覆盖创建方法以使用销售订单中的当前数据进行采购订单,并且我的代码不起作用 我试试这个:

@api.multi

def creat(self):     #为自己的订单:     #order.state =' sale'     #order.confirmation_date = fields.Datetime.now()     #if self.env.context.get(' send_email'):     #self.force_quotation_send()     #order.order_line._action_procurement_create()     #if self.env [' ir.values']。get_default(' sale.config.settings',' auto_done_setting'):     #self.action_done()

    self.env['purchase.order'].create({'partner_id': partner_id.id,
        'location_id':location_id.id,
        'pricelist_id': pricelist_id.id,
        'order_line': [(0, 0, {'product_id': product_id.id,
           'name': name.id,
           'date_planned': date_planned.id,
            'price_unit': price_unit.id})]})
    return True

1 个答案:

答案 0 :(得分:0)

您必须将api.model用于create方法,因为创建新记录时记录没有id。

这是一个示例代码

@api.model
def create(self, vals):
    res = super(ClassName, self).create(vals)
    # Your code here 
    # vals will contain dictionary of all variables.      
    return res

此外,您无需更改用于从销售中创建采购订单的代码。 您只需为产品和产品供应商设置路线(在本例中为购买)。