在Odoo 14或Flectra 1.7中点击创建发票时,如何将销售订单中的数据传输到发票? [英] How Do I transfer data from sale order to invoice when clicking on 'Create Invoice' in Odoo 14 or Flectra 1.7?

查看:33
本文介绍了在Odoo 14或Flectra 1.7中点击创建发票时,如何将销售订单中的数据传输到发票?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Docker容器中运行Flectra。我要将sale.order中的自定义字段传输到account t.Invoice

class SaleOrder(models.Model):
    _inherit = 'sale.order' 
    myField = fields.Integer(string='My Field', default=21, required = True)

    @api.multi
    def _prepare_invoice(self):
         res = super(SaleOrder, self)._prepare_invoice()
         # res.update({
         #     'myField': self.myField,
         # })
         res['myField'] = self.myField
         return res


class SaleInvoice(models.Model):
    _inherit = 'account.invoice' 
    myField = fields.Integer(string='My Field', default=21, required = True)

我尝试在不同的变体中覆盖_PREPARE_INVOICE_CREATE_INVOICES,但都不起作用。根据我的理解,它们应该是有效的,但我是新来Odoo/Flectra的,所以如果有任何帮助,我会很高兴。

我使用的是Flectra 1.7(社区版),我认为它对应于Odoo 14。

推荐答案

尝试此操作:

def create_invoice(self):
    for rec in self:
        invoice = rec.env['account.move'].create({
            'move_type': 'out_invoice',
            # 'partner_id': self.partner.id, 
            'journal_id': 18, # say u forget to create journal 
            # 'currency_id': self.env.ref('base.USD').id, 
            'payment_reference': 'invoice to client',  

            'invoice_line_ids': [(0, 0, {
                'product_id': self.env['product.product'].create({'name': 'A Test Product'}),
                'quantity': 1,
                'price_unit': 40,
                'name': 'Your project product',
            })],
        })

这篇关于在Odoo 14或Flectra 1.7中点击创建发票时,如何将销售订单中的数据传输到发票?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆