我已经安装了一个自定义模块从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
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。