Přejít na obsah
Odoo Menu
  • Přihlásit se
  • Vyzkoušejte zdarma
  • Aplikace
    Finance
    • Účetnictví
    • Fakturace
    • Výdaje
    • Spreadsheet (BI)
    • Dokumenty
    • Podpisy
    Prodej
    • CRM
    • Prodej
    • POS Obchod
    • POS Restaurace
    • Předplatné
    • Pronájem
    Webové stránky
    • Webové stránky
    • E-shop
    • Blog
    • Fórum
    • Živý chat
    • eLearning
    Dodavatelský řetězec
    • Sklad
    • Výroba
    • PLM
    • Nákup
    • Údržba
    • Kvalita
    Lidské zdroje
    • Zaměstnanci
    • Nábor
    • Volno
    • Hodnocení zaměstnanců
    • Doporučení
    • Vozový park
    Marketing
    • Marketing sociálních sítí
    • Emailový marketing
    • SMS Marketing
    • Události
    • Marketingová automatizace
    • Dotazníky
    Služby
    • Projekt
    • Časové výkazy
    • Práce v terénu
    • Helpdesk
    • Plánování
    • Schůzky
    Produktivita
    • Diskuze
    • Schvalování
    • IoT
    • VoIP
    • Znalosti
    • WhatsApp
    Aplikace třetích stran Odoo Studio Odoo cloudová platforma
  • Branže
    Maloobchod
    • Knihkupectví
    • Obchod s oblečením
    • Obchod s nábytkem
    • Potraviny
    • Obchod s hardwarem
    • Hračkářství
    Jídlo a pohostinství
    • Bar a Pub
    • Restaurace
    • Fast Food
    • Penzion
    • Distributor nápojů
    • Hotel
    Nemovitost
    • Realitní kancelář
    • Architektonická firma
    • Stavba
    • Správa nemovitostí
    • Zahradnictví
    • Asociace vlastníků nemovitosti
    Poradenství
    • Účetní firma
    • Odoo Partner
    • Marketingová agentura
    • Právník
    • Akvizice talentů
    • Audit a certifikace
    Výroba
    • Textil
    • Kov
    • Nábytek
    • Jídlo
    • Pivovar
    • Korporátní dárky
    Zdraví a fitness
    • Sportovní klub
    • Prodejna brýli
    • Fitness Centrum
    • Wellness praktikové
    • Lékárna
    • Kadeřnictví
    Transakce
    • Údržbář
    • Podpora IT & hardware
    • Systémy solární energie
    • Výrobce obuvi
    • Úklidové služby
    • Služby HVAC
    Ostatní
    • Nezisková organizace
    • Agentura pro životní prostředí
    • Pronájem billboardů
    • Fotografování
    • Leasing jízdních kol
    • Prodejce softwaru
    Procházet všechna odvětví
  • Komunita
    Edukační program
    • Tutoriály
    • Dokumentace
    • Certifikace
    • Vzdělávání
    • Blog
    • Podcast
    Podpora vzdělávání
    • Vzdělávací program
    • Scale Up! Hra na firmu
    • Navštivte Odoo
    Získat software
    • Stáhnout
    • Porovnejte edice
    • Verze
    Spolupráce
    • Github
    • Fórum
    • Události
    • Překlady
    • Stát se partnerem
    • Služby pro partnery
    • Registrujte svou účetní firmu
    Získat služby
    • Najít partnera
    • Najít účetní
    • Setkejte se s poradcem
    • Implementační služby
    • Zákaznické reference
    • Podpora
    • Upgrady
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Dohodnout demo
  • Ceník
  • Pomoc

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

  • CRM
  • e-Commerce
  • Účetnictví
  • Sklad
  • PoS
  • Projekty
  • MRP
All apps
You need to be registered to interact with the community.
All Posts Lidé Odznaky
Štítky (View all)
odoo accounting v14 pos v15
O tomto fóru
You need to be registered to interact with the community.
All Posts Lidé Odznaky
Štítky (View all)
odoo accounting v14 pos v15
O tomto fóru
Pomoc

Odoo 11 insert invoice_line_ids from stock.move data

Odebírat

Get notified when there's activity on this post

This question has been flagged
odoo11odoo11communityOdoo11Odoo11.011.0
2 Odpovědi
6799 Zobrazení
Avatar
Ignacio Raga

Hi there! I'm developing a custom module that allows users to add related stock moves to invoices. I want each one of this related stock moves added as an invoice line to the current invoice so I'm trying to create an invoice_line_ids from this related stock moves but its not working. I've been doing some modifications to the code and I get several errors, but I can't understand why the code is not working properly.


Here is my custom view

<odoo>
	<record id="invoice_stock_moves" model="ir.ui.view">
	    <field name="name">account.invoice.related_stock_moves</field>
	    <field name="model">account.invoice</field>
	    <field name="inherit_id" ref="account.invoice_supplier_form"/>
	    <field name="arch" type="xml">
	        <xpath expr="//page" position="after">
				<page string="Movimientos asociados" attrs="{'invisible': [('partner_id', '=', False)]}">
					<field name="related_stock_moves" widget="many2many" options="{'no_create': True}" domain="['&amp;', ('state','=','done'), ('picking_partner_id','=',context.get('partner_id')), '&amp;', ('x_invoice_id','=',False)]" attrs="{'readonly':[('state','not in',('draft',))]}">
					  <tree>
						<field name="state" invisible="1"/>
						<field name="date" />
						<field name="picking_partner_id" invisible="1"/>
						<field name="reference" />
						<field name="product_id" />
						<field name="product_uom_qty" string="Cantidad" />
						<field name="product_uom" />
					  </tree>
					</field>
				</page>
	        </xpath>
	    </field>
	</record>
</odoo>


And here my .py defining the model

# -*- coding: utf-8 -*-
from odoo import api, fields, models

import logging
_logger = logging.getLogger(__name__)

class Move(models.Model):
    _inherit = 'stock.move'


    x_invoice_id = fields.Many2one('account.invoice',
        string="Factura de referencia", ondelete='set null')


class Invoice(models.Model):
    _inherit = 'account.invoice'

    related_stock_moves = fields.One2many('stock.move',
        'x_invoice_id', 'related_stock_moves', string="Movimiento asociado")


    invoice_line_ids = fields.One2many('account.invoice.line',
        'invoice_id', string="Líneas de la factura", compute='_add_lines')

## Retrieve product_id and product_uom_qty
    @api.depends('related_stock_moves')
    @api.one
    def _add_lines(self):
        for move in self.related_stock_moves:
            self.env['account.invoice.line'].create({
                    'account_id': self.account_id.id,
                    'invoice_id': self.id,
                    'product_id': move.product_id.id,
                    'quantity': move.product_uom_qty,
                    'name': move.product_id.description,
                    'price_unit': '0.0'
            })

I'm not sure if I should be using a computed field, I want the invoice lines added when a related stock move is added. 


Any help is kindly appreciated, thanks for your time <3

0
Avatar
Zrušit
Begineer

I have updated my answer for your requirement, please check to it.

Avatar
Begineer
Nejlepší odpověď

Hello,

You can do this by using a button function.

In .py

@api.multi

def action_add_lines(self):

    invoice_line_obj = self.env['account.invoice.line']

    for each in self:

        for move in each.related_stock_moves:

            invoice_line_obj.create({

            'account_id': each.account_id.id, 
            'invoice_id': each.id,
            'product_id': move.product_id.id,
            'quantity': move.product_uom_qty,
            'name': move.product_id.description,
            'price_unit': '0.0'

})            
    return True

In xml,

You can define the button using xpath since your inheriting account.invoice,

<record model="ir.ui.view" id="invoice_form_inherit">

            <field name="name">account.invoice.form</field>

            <field name="model">account.invoice</field>

            <field name="inherit_id" ref="account.invoice_form"/>

            <field name="arch" type="xml">

            <xpath expr="/form/header/button[@name='action_invoice_open']" position="after">

                <button name="action_add_lines" string="Add Lines" type="object" class="oe_highlight" states="draft"/>

            </xpath>

            </field>

</record>


Okay without a button function you can do it by onchange of related_stock_moves field,

class Invoice(models.Model):

    _inherit = 'account.invoice'

    

    @api.onchange('related_stock_moves')   

    def onchange_related_stock_moves(self):

        if self.related_stock_moves:

            new_lines = self.env['account.invoice.line']

            for move in self.related_stock_moves - self.invoice_line_ids.mapped('stock_move_id'):

                data = {

                    'account_id': self.account_id.id, 

                    'invoice_id': self.id, 

                    'product_id': move.product_id.id, 

                    'quantity': move.product_uom_qty, 

                    'name': move.product_id.description, 

                    'price_unit': 0.0

                    'stock_move_id': move.id

                }

                new_line = new_lines.new(data)

                new_lines += new_line

            self.invoice_line_ids = new_lines

        return {}

        

class InvoiceLine(models.Model):

    _inherit = 'account.invoice.line'


    stock_move_id = fields.Many2one('stock.move', string='Stock Move')


In order to do this, you should have a many2one link of stock move in account.invoice.line

0
Avatar
Zrušit
Avatar
Ignacio Raga
Autor Nejlepší odpověď

Thanks @Karthikeyan N R, I've been able to add the invoice lines with your action button. I'll be trying now to do this without requiring a button click from the user and I will share the updates here :)

status of my code atm

.py
from odoo import api, fields, models

import logging
_logger = logging.getLogger(__name__)

class Move(models.Model):
    _inherit = 'stock.move'


    x_invoice_id = fields.Many2one('account.invoice',
        string="Factura de referencia", ondelete='set null')


class Invoice(models.Model):
    _inherit = 'account.invoice'

    related_stock_moves = fields.One2many('stock.move',
        'x_invoice_id', string="Movimiento asociado")


    @api.multi
    def action_add_lines(self):
        invoice_line_obj = self.env['account.invoice.line']
        for each in self:
            for move in each.related_stock_moves:
                rec = {
                    'account_id': each.account_id.id,
                    'invoice_id': each.id,
                    'product_id': move.product_id.id,
                    'quantity': move.product_uom_qty,
                    'name': move.product_id.name,
                    'price_unit': '0.0'
                }
                invoice_line_obj.create(rec)
        return True
my custom view

<odoo>
	<record id="invoice_stock_moves" model="ir.ui.view">
	    <field name="name">account.invoice.related_stock_moves</field>
	    <field name="model">account.invoice</field>
	    <field name="inherit_id" ref="account.invoice_supplier_form"/>
	    <field name="arch" type="xml">
	        <xpath expr="//page" position="after">
				<page string="Movimientos asociados" attrs="{'invisible': [('partner_id', '=', False)]}">
					<field name="related_stock_moves" widget="many2many" options="{'no_create': True}" domain="['&amp;', ('state','=','done'), ('picking_partner_id','=',context.get('partner_id')), '&amp;', ('x_invoice_id','=',False)]" attrs="{'readonly':[('state','not in',('draft',))]}">
					  <tree>
						<field name="state" invisible="1"/>
						<field name="date" />
						<field name="picking_partner_id" invisible="1"/>
						<field name="reference" />
						<field name="product_id" />
						<field name="product_uom_qty" string="Cantidad" />
						<field name="product_uom" />
					  </tree>
					</field>
					<button name="action_add_lines" string="Añadir a factura" type="object" class="oe_highlight" states="draft"/>
				</page>
	        </xpath>
	</record>
</odoo>
I'm still trying to understand how to do this without requiring a button click
0
Avatar
Zrušit
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Přihlásit se
Related Posts Odpovědi Zobrazení Aktivita
Odoo Date Total In Version 11 Vyřešeno
odoo11 odoo11community odoo11.0 Odoo11
Avatar
Avatar
Avatar
3
bře 19
4325
py3o template report
reporting odoo11 odoo11community odoo11.0 Odoo11.0
Avatar
0
srp 25
1314
how to pass element tree to other function TypeError: 'ElementTree' object is not iterable - - -
odoo11 odoo12.0 odoo11community odoo11.0 Odoo11
Avatar
Avatar
1
kvě 20
7598
Hide field using One2many domain Vyřešeno
domain odoo11 odoo11community odoo11.0 Odoo11
Avatar
Avatar
1
led 19
6880
Menu dropdown_click outside to collapse
odoo odoo11 odoo11community odoo11.0 Odoo11
Avatar
Avatar
Avatar
3
pro 18
9860
Komunita
  • Tutoriály
  • Dokumentace
  • Fórum
Open Source
  • Stáhnout
  • Github
  • Runbot
  • Překlady
Služby
  • Odoo.sh hostování
  • Podpora
  • Upgrade
  • Nestandardní vývoj
  • Edukační program
  • Najít účetní
  • Najít partnera
  • Stát se partnerem
O nás
  • Naše společnost
  • Podklady značky
  • Kontakujte nás
  • Práce
  • Události
  • Podcast
  • Blog
  • Zákazníci
  • Právní dokumenty • Soukromí
  • Zabezpečení
الْعَرَبيّة 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 je balíček open-source aplikací, které pokrývají všechny potřeby vaší společnosti: CRM, e-shop, účetnictví, sklady, kasy, projektové řízení a další.

Unikátní nabídka od Odoo poskytuje velmi jednoduché uživatelské rozhraní a vše je integrované na jednom místě.

Website made with

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