我在sale.order.line
中有一个自定义字段
scheme = fields.Many2one('scheme')
与此相同,account.invoice.line
中的字段也为
scheme = fields.Many2one('scheme')
将销售订单转换为发票时,我想将值从sale.order.line
复制到account.inovice.line
。
我怎么能这样做?
我尝试在继承的类中覆盖函数(在单击创建发票按钮时调用),但该函数未执行。我怎么能这样做?
我试过这样的事情,但功能没有执行..
def _prepare_advance_invoice_vals(self, cr, uid, ids, context=None):
......
.....
# create the invoice
inv_line_values = {
'name': res.get('name'),
'origin': sale.name,
'account_id': res['account_id'],
'price_unit': inv_amount,
'quantity': wizard.qtty or 1.0,
'discount': False,
'uos_id': res.get('uos_id', False),
'product_id': wizard.product_id.id,
'invoice_line_tax_id': res.get('invoice_line_tax_id'),
'account_analytic_id': sale.project_id.id or False,
'scheme':sale.scheme,
}
inv_values = {
'name': sale.client_order_ref or sale.name,
'origin': sale.name,
'type': 'out_invoice',
'reference': False,
'account_id': sale.partner_id.property_account_receivable.id,
'partner_id': sale.partner_invoice_id.id,
'invoice_line': [(0, 0, inv_line_values)],
'currency_id': sale.pricelist_id.currency_id.id,
'comment': sale.note,
'payment_term': sale.payment_term.id,
'fiscal_position': sale.fiscal_position.id or sale.partner_id.property_account_position.id,
'section_id': sale.section_id.id,
'scheme':sale.scheme,(custom field)
}
result.append((sale.id, inv_values))
return_value = super(account_advance_inv, self)._prepare_advance_invoice_vals(result)
return return_value
答案 0 :(得分:2)
在销售模块中覆盖sale.py中的 _prepare_invoice_line 方法。
@api.multi
def _prepare_invoice_line(self, qty):
...
...
res = {
'name': self.name,
'sequence': self.sequence,
'origin': self.order_id.name,
'account_id': account.id,
'price_unit': self.price_unit,
'quantity': qty,
'discount': self.discount,
'uom_id': self.product_uom.id,
'product_id': self.product_id.id or False,
'invoice_line_tax_ids': [(6, 0, self.tax_id.ids)],
'account_analytic_id': self.order_id.project_id.id,
'scheme' : self.scheme.id
}
return res
在res字典中添加您的字段,如上面的代码所示。