Pular para o conteúdo
Odoo Menu
  • Entrar
  • Experimente grátis
  • Aplicativos
    Finanças
    • Financeiro
    • Faturamento
    • Despesas
    • Planilhas (BI)
    • Documentos
    • Assinar Documentos
    Vendas
    • CRM
    • Vendas
    • PDV Loja
    • PDV Restaurantes
    • Assinaturas
    • Locação
    Websites
    • Criador de Sites
    • e-Commerce
    • Blog
    • Fórum
    • Chat ao Vivo
    • e-Learning
    Cadeia de mantimentos
    • Inventário
    • Fabricação
    • PLM - Ciclo de Vida do Produto
    • Compras
    • Manutenção
    • Qualidade
    Recursos Humanos
    • Funcionários
    • Recrutamento
    • Folgas
    • Avaliações
    • Indicações
    • Frota
    Marketing
    • Redes Sociais
    • Marketing por E-mail
    • Marketing por SMS
    • Eventos
    • Automação de Marketing
    • Pesquisas
    Serviços
    • Projeto
    • Planilhas de Horas
    • Serviço de Campo
    • Central de Ajuda
    • Planejamento
    • Compromissos
    Produtividade
    • Mensagens
    • Aprovações
    • Internet das Coisas
    • VoIP
    • Conhecimento
    • WhatsApp
    Aplicativos de terceiros Odoo Studio Plataforma Odoo Cloud
  • Setores
    Varejo
    • Loja de livros
    • Loja de roupas
    • Loja de móveis
    • Mercearia
    • Loja de ferramentas
    • Loja de brinquedos
    Comida e hospitalidade
    • Bar e Pub
    • Restaurante
    • Fast Food
    • Hospedagem
    • Distribuidor de bebidas
    • Hotel
    Imóveis
    • Imobiliária
    • Escritório de arquitetura
    • Construção
    • Administração de propriedades
    • Jardinagem
    • Associação de proprietários de imóveis
    Consultoria
    • Escritório de Contabilidade
    • Parceiro Odoo
    • Agência de marketing
    • Escritório de advocacia
    • Aquisição de talentos
    • Auditoria e Certificação
    Fabricação
    • Têxtil
    • Metal
    • Móveis
    • Alimentação
    • Cervejaria
    • Presentes corporativos
    Saúde e Boa forma
    • Clube esportivo
    • Loja de óculos
    • Academia
    • Profissionais de bem-estar
    • Farmácia
    • Salão de cabeleireiro
    Comércio
    • Handyman
    • Hardware e Suporte de TI
    • Sistemas de energia solar
    • Sapataria
    • Serviços de limpeza
    • Serviços de climatização
    Outros
    • Organização sem fins lucrativos
    • Agência Ambiental
    • Aluguel de outdoors
    • Fotografia
    • Aluguel de bicicletas
    • Revendedor de software
    Navegar por todos os setores
  • Comunidade
    Aprenda
    • Tutoriais
    • Documentação
    • Certificações
    • Treinamento
    • Blog
    • Podcast
    Empodere a Educação
    • Programa de educação
    • Scale Up! Jogo de Negócios
    • Visite a Odoo
    Obtenha o Software
    • Baixar
    • Comparar edições
    • Releases
    Colaborar
    • Github
    • Fórum
    • Eventos
    • Traduções
    • Torne-se um parceiro
    • Serviços para parceiros
    • Cadastre seu escritório contábil
    Obtenha os serviços
    • Encontre um parceiro
    • Encontre um Contador
    • Conheça um consultor
    • Serviços de Implementação
    • Referências de Clientes
    • Suporte
    • Upgrades
    Github YouTube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Faça uma demonstração
  • Preços
  • Ajuda

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Financeiro
  • Inventário
  • PoS
  • Projeto
  • MRP
All apps
É necessário estar registrado para interagir com a comunidade.
Todas as publicações Pessoas Emblemas
Marcadores (Ver tudo)
odoo accounting v14 pos v15
Sobre este fórum
É necessário estar registrado para interagir com a comunidade.
Todas as publicações Pessoas Emblemas
Marcadores (Ver tudo)
odoo accounting v14 pos v15
Sobre este fórum
Ajuda

How to transfer data from sale order to invoice when clicking on 'Create Invoice'?

Inscrever

Seja notificado quando houver atividade nesta publicação

Esta pergunta foi sinalizada
wizardinvoicequotationact_windowodoo8.0
3 Respostas
15852 Visualizações
Avatar
Yenthe Van Ginneken (Mainframe Monkey)

Hi guys,

I'm extending the sale and account module and added my custom fields in a custom module. I've added fields in both the sale.order.line model and the account.invoice.line model:

class custom_sale_order_line_fields(models.Model):
    _inherit = 'sale.order.line'
    hoogte = fields.Integer()
    breedte = fields.Integer()
    aantal = fields.Integer()
    #Checkboxes
    links = fields.Boolean()
    rechts = fields.Boolean()
    boven = fields.Boolean()
    onder = fields.Boolean()
    kleur = fields.Selection((('w','Wit'), ('z','Zwart'), ('g','Groen'),('r','Rood')))

class aa_invoice_custom_lines(models.Model):
    _inherit = 'account.invoice.line'
    hoogte = fields.Integer()
    breedte = fields.Integer()
    aantal = fields.Integer()
    #Checkboxes
    links = fields.Boolean()
    rechts = fields.Boolean()
    boven = fields.Boolean()
    onder = fields.Boolean()
    kleur = fields.Selection((('w','wit'), ('z','zwart'), ('g','groen'),('r','rood')))

The fields are added in both the view for a new sale order and the view for an invoice:

 <openerp>
    <data>
        <record id="sale.view_order_form_inherit" model="ir.ui.view">
            <field name="name">sale.order.form.inherit</field>
            <field name="model">sale.order</field>
            <field name="inherit_id" ref="sale.view_order_form"/>
 	    <field name="arch" type="xml">
	        <xpath expr="//tree[@string='Sales Order Lines']/field[@name='name']" position="after">
		    <field name="links"/>
		    <field name="rechts"/>
		    <field name="boven"/>
		    <field name="onder"/>
		    <field name="kleur"/>
                    <field name="hoogte" on_change="on_change_hoeveelheid_berekenen(hoogte,breedte,aantal)"/>
		    <field name="breedte" on_change="on_change_hoeveelheid_berekenen(hoogte,breedte,aantal)"/>
                    <field name="aantal" on_change="on_change_hoeveelheid_berekenen(hoogte,breedte,aantal)"/>
		</xpath>
	    </field>
        </record>

        <record id="account.invoice_form_inherit3" model="ir.ui.view">
            <field name="name">account.invoice.form.inherit3</field>
            <field name="model">account.invoice</field>
            <field name="inherit_id" ref="account.invoice_form"/>
 	    <field name="arch" type="xml">
	        <xpath expr="//tree[@string='Invoice Lines']/field[@name='name']" position="after">
		    <field name="links"/>
		    <field name="rechts"/>
		    <field name="boven"/>
		    <field name="onder"/>
		    <field name="kleur"/>
                    <field name="hoogte" on_change="on_change_hoeveelheid_factuur_berekenen(hoogte,breedte,aantal)"/>
		    <field name="breedte" on_change="on_change_hoeveelheid_factuur_berekenen(hoogte,breedte,aantal)"/>
                    <field name="aantal" on_change="on_change_hoeveelheid_factuur_berekenen(hoogte,breedte,aantal)"/>
		</xpath>
	    </field>
        </record>
    </data>
</openerp>

The next thing that I need is that when the user opens up a sales order and clicks on the button 'Create Invoice' that the filled in data from the sales order gets passed on to the invoice that is automatically generated.
The button 'Create Invoice' seems to come from /sale/wizard/sale_line_invoice.xml from this record:

 <record id="action_view_sale_order_line_make_invoice" model="ir.actions.act_window">
            <field name="name">Create Invoice</field>
            <field name="type">ir.actions.act_window</field>
            <field name="res_model">sale.order.line.make.invoice</field>
            <field name="view_type">form</field>
            <field name="view_mode">form</field>
            <field name="view_id" ref="view_sale_order_line_make_invoice"/>
            <field name="target">new</field>
        </record>

What I don't understand now is where I should add the logic to transfer data from my custom fields from a sales order to an invoice. How do I know which code this action triggers and how should I transfer the data from the sale order to the invoice? It looks like the data is transferred in the method make_invoice (addons/sale/wizard/sale_line_invoice.py in the following lines:

 #TODO: merge with sale.py/make_invoice
        def make_invoice(order, lines):
            """
                 To make invoices.

                 @param order:
                 @param lines:

                 @return:

            """
            a = order.partner_id.property_account_receivable.id
            if order.partner_id and order.partner_id.property_payment_term.id:
                pay_term = order.partner_id.property_payment_term.id
            else:
                pay_term = False
            inv = {
                'name': order.client_order_ref or '',
                'origin': order.name,
                'type': 'out_invoice',
                'reference': "P%dSO%d" % (order.partner_id.id, order.id),
                'account_id': a,
                'partner_id': order.partner_invoice_id.id,
                'invoice_line': [(6, 0, lines)],
                'currency_id' : order.pricelist_id.currency_id.id,
                'comment': order.note,
                'payment_term': pay_term,
          
                'fiscal_position': order.fiscal_position.id or order.partner_id.property_account_position.id,
                'user_id': order.user_id and order.user_id.id or False,
                'company_id': order.company_id and order.company_id.id or False,
                'date_invoice': fields.date.today(),
            }
            inv_id = self.pool.get('account.invoice').create(cr, uid, inv)
            return inv_id
But how can I add my custom fields to be added on the invoice lines too?

Thanks,
Yenthe
1
Avatar
Cancelar
Avatar
Peter Alabaster
Melhor resposta

I have done this before when adding lots to all sale, purchase, and invoice lines. I had to pipe the data across all these forms.

You have to do a certain amount of rooting around in the source code to find the right place to hook in, but for your situation this should work:

class sale_order_line_your_extension(osv.osv):
_inherit = "sale.order.line"

def _prepare_order_line_invoice_line(self, cr, uid, line, account_id=False, context=None):
    ret = super(sale_order_line_your_extension, self)._prepare_order_line_invoice_line(cr, uid, line, account_id=False, context=context)
    if line.product_id:
        if line.field_name:
            ret['field_name'] = line.field_name
    return ret

Note: super has been used here to reduce impact on source code.

All we are doing is assigning all the default returned values in the source code to the variable `ret`.

We are then checking if line.product_id exists on the sale order.

Then checking if anything has been set on your field, and then appending your field name (as defined in account.invoice.line) to ret, and assigning the value stored in the field to it.

Finally the appended value is returned, along with all other values.

This can be used in many places when piping data across forms, and can be quite a useful template.

You can easily add more than one value:

ret['field_name2'] = line.field_name2

ret['field_name3'] = line.field_name3

Hope this helps

6
Avatar
Cancelar
Yenthe Van Ginneken (Mainframe Monkey)
Autor

Thanks Peter! This is a really great answer which is also usuable for other cases. Upvoted & accepted, again thanks! :)

Avatar
Tintumon
Melhor resposta

 For creating "account.invoice" from "sale.order" there is four selection option

  • delivered

  • all

  • percentage

  • fixed

I tried a function "def action_invoice_create(self, grouped=False, final=False): " using super in inherited sale.order.

It works fine for sending a field value from sale.order to account.invoice, when the selection field is "delivered" or "all".

But it doesn't work for "percentage" and "fixed" selections.

So I used another function "def _create_invoice(self, order, so_line, amount):"  using super in inherited wizard/sale_make_invoice_advance.py

It propagated the field value from sale.order to account.invoice successfully.

I have tested it in debug also.

Does it right way to achieve? or any other way?

Note: I worked on ODOO9

0
Avatar
Cancelar
Coralie Cardon

Hello ! I did exactely what you say :-) but i have a problem So, I have a rate in my sale order and i would like take it to multiply to the amount of my invoice. (I put it in a field) But the amount doesn't take the down payment

Está gostando da discussão? Não fique apenas lendo, participe!

Crie uma conta hoje mesmo para aproveitar os recursos exclusivos e interagir com nossa incrível comunidade!

Inscreva-se
Publicações relacionadas Respostas Visualizações Atividade
Enlarge or change width of text in invoice/quotation reports Resolvido
invoice quotation
Avatar
Avatar
2
fev. 23
3464
Change invoice footer per country
invoice odoo8.0
Avatar
Avatar
Avatar
3
jul. 17
5200
How to make a new field and being integrated in 2 modules
invoice quotation
Avatar
Avatar
1
mai. 16
4246
How can modify the N° or the source of document for the quotation Resolvido
invoice quotation
Avatar
Avatar
2
abr. 16
5019
How can I edit Sales Tax so that it doesn't show the rate, just the word "Tax"? Resolvido
invoice tax quotation
Avatar
Avatar
1
out. 25
3751
Comunidade
  • Tutoriais
  • Documentação
  • Fórum
Open Source
  • Baixar
  • Github
  • Runbot
  • Traduções
Serviços
  • Odoo.sh Hosting
  • Suporte
  • Upgrade
  • Desenvolvimentos personalizados
  • Educação
  • Encontre um Contador
  • Encontre um parceiro
  • Torne-se um parceiro
Sobre nós
  • Nossa empresa
  • Ativos da marca
  • Contato
  • Empregos
  • Eventos
  • Podcast
  • Blog
  • Clientes
  • Legal • Privacidade
  • Segurança
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo é um conjunto de aplicativos de negócios em código aberto que cobre todas as necessidades de sua empresa: CRM, comércio eletrônico, contabilidade, estoque, ponto de venda, gerenciamento de projetos, etc.

A proposta de valor exclusiva Odoo é ser, ao mesmo tempo, muito fácil de usar e totalmente integrado.

Site feito com

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now