开发者社区> 问答> 正文

从odoo的订单线上获得产品价格?

我已经安装了一个自定义模块从Odoo商店,它会自动创建一个信用记录的产品,但这个模块从产品的形式,其中可能不包括订单的价格。 我需要改变每一行的价格的价值计算从订单线,即使它是在出售或购买。 这是创建方法:

@api.multi   
def create_refund_invoice(self):   
    inv_obj = self.env['account.invoice']
    for pick in self.filtered(lambda x:x.return_type):
        type = 'in_refund' if pick.return_type == 'purchase' else 'out_refund'
        inv_lines = {'type':type, 'partner_id':pick.partner_id.id, 'invoice_line_ids':[]}
        account = pick.return_type == 'sale' and pick.partner_id.property_account_receivable_id.id or pick.partner_id.property_account_payable_id.id
        inv_lines['account_id'] = account
        inv_lines['origin'] = pick.name
        inv_lines['name'] = pick.origin
        for line in pick.move_lines:
            name = line.product_id.partner_ref
            pricelist_id = pick.partner_id.property_product_pricelist
            price = pricelist_id.get_product_price(line.product_id, 1, pick.partner_id) if pricelist_id else line.product_id.lst_price


            inv_lines['invoice_line_ids'] += [(0, None, {'product_id':line.product_id.id,
                                   'name':name,
                                   'quantity':line.quantity_done,
                                   'price_unit': price,
                                   'account_id':line.product_id.product_tmpl_id.get_product_accounts()['income'].id})]
        if inv_lines['invoice_line_ids']:
            inv_id = inv_obj.create(inv_lines)
            pick.invoice_id = inv_id.id

我该怎么办? 我试着设置

 price = line.env['purchase.order'].search([('name','=',line.group_id)]).order_line.price_unit

但它使价格= 0 任何帮助将不胜感激。 我使它,但它只得到一条记录,如果有不止一条记录,我得到错误

 raise ValueError("Expected singleton: %s" % self) ValueError: Expected singleton: purchase.order.line(11362, 11363)

这是新方法

@api.multi
def create_refund_invoice(self):
    inv_obj = self.env['account.invoice']
    for pick in self.filtered(lambda x:x.return_type):
        type = 'in_refund' if pick.return_type == 'purchase' else 'out_refund'
        inv_lines = {'type':type, 'partner_id':pick.partner_id.id, 'invoice_line_ids':[]}
        account = pick.return_type == 'sale' and pick.partner_id.property_account_receivable_id.id or pick.partner_id.property_account_payable_id.id
        inv_lines['account_id'] = account
        inv_lines['origin'] = pick.name
        inv_lines['name'] = pick.origin
        for line in pick.move_lines:
            name = line.product_id.partner_ref
            order_id = line.env['purchase.order'].search([('name', '=', line.origin)]).order_line
            price = order_id.price_unit
            inv_lines['invoice_line_ids'] += [(0, None, {
                'product_id':line.product_id.id,
                'name':name,
                'quantity':line.quantity_done,
                'price_unit': price,
                'account_id':line.product_id.product_tmpl_id.get_product_accounts()['income'].id})]
        if inv_lines['invoice_line_ids']:
            inv_id = inv_obj.create(inv_lines)
            pick.invoice_id = inv_id.id

问题来源StackOverflow 地址:/questions/59380022/get-product-price-from-order-line-in-odoo

展开
收起
kun坤 2019-12-30 09:58:58 634 0
0 条回答
写回答
取消 提交回答
问答地址:
问答排行榜
最热
最新

相关电子书

更多
《淘宝推荐业务介绍》 立即下载
电商的线上业务安全 立即下载
余额宝超大规模基金文件处理——分布式调度组件:余额宝大白组件 立即下载