Odoo 将自定义字段值从销售订单传递到发票
我需要将自定义字段值从“销售订单表单”视图传递到“发票表单”视图中的发票行。像odoo一样,将产品详细信息从销售订单传递到发票行。奥多用什么方法?它是一个开/关功能吗Odoo 将自定义字段值从销售订单传递到发票,odoo,Odoo,我需要将自定义字段值从“销售订单表单”视图传递到“发票表单”视图中的发票行。像odoo一样,将产品详细信息从销售订单传递到发票行。奥多用什么方法?它是一个开/关功能吗 def prepare_invoice(self, cr, uid, order, lines, context=None): """Prepare the dict of values to create the new invoice for a sales order. This method may
def prepare_invoice(self, cr, uid, order, lines, context=None):
"""Prepare the dict of values to create the new invoice for a
sales order. This method may be overridden to implement custom
invoice generation (making sure to call super() to establish
a clean extension chain).
:param browse_record order: sale.order record to invoice
:param list(int) line: list of invoice line IDs that must be
attached to the invoice
:return: dict of value to create() the invoice
"""
order=self.browse(cr,uid,lines,context=context)
if context is None:
context = {}
journal_ids = self.pool.get('account.journal').search(cr, uid,
[('type', '=', 'sale'), ('company_id', '=', order.company_id.id)],
limit=1)
# if not journal_ids:
# raise osv.except_osv(_('Error!'),
# _('Please define sales journal for this company: "%s" (id:%d).') % (order.company_id.name, order.company_id.id))
invoice_vals = {
'name': order.client_order_ref or '',
'origin': order.name,
'type': 'out_invoice',
'reference': order.client_order_ref or order.name,
'account_id': order.partner_invoice_id.property_account_receivable.id,
'partner_id': order.partner_invoice_id.id,
'journal_id': journal_ids[0],
'invoice_line': [(6, 0, lines)],
'currency_id': order.pricelist_id.currency_id.id,
'comment': order.note,
'payment_term': order.payment_term and order.payment_term.id or False,
'fiscal_position': order.fiscal_position.id or order.partner_invoice_id.property_account_position.id,
'date_invoice': context.get('date_invoice', False),
'company_id': order.company_id.id,
'user_id': order.user_id and order.user_id.id or False,
'section_id' : order.section_id.id,
'Order' : order.Order
}
# Care for deprecated _inv_get() hook - FIXME: to be removed after 6.1
invoice_vals.update(self._inv_get(cr, uid, order, context=context))
return invoice_vals
我已经准备好从sale.py重写这个方法了。我应该在哪里调用此方法来自动传递字段值
@api.v7
def _prepare_invoice(self, cr, uid, order, lines, context=None):
res=super(Inherit_so, self)._prepare_invoice(cr, uid, order, lines, context=context)
inv_obj = self.pool.get('account.invoice.line')
inv_obj.write(cr, uid, lines, {'Order': order.Order.id}, context=context)
inv_obj.write(cr, uid, lines, {'staff': order.staff.id}, context=context)
return res
覆盖sale.py创建account.invoice from sale.order的方法有四个选择选项 交付 全部的 百分率 固定的 我尝试了一个函数def action_invoice_createself,grouped=False,final=False:在继承的sale.order中使用super。当选择字段已交付或全部交付时,它可以将字段值从sale.order发送到account.invoice 代替def action\u invoice\u createself,grouped=False,final=False:我尝试了def\u prepare\u invoiceself,cr,uid,order,line,context=None:也。但同样的事情发生了,它不适用于百分比和固定选择 因此,我使用了另一个函数def _create _invoiceself、order、So _line、amount:在继承的向导/sale _make _invoice _advance.py中使用super 它成功地将字段值从sale.order传播到account.invoice。我也在调试中测试了它 这是实现目标的正确途径吗?还是其他方式 注意:我在ODOO9上工作过