Se rendre au contenu
Odoo Menu
  • Se connecter
  • Essai gratuit
  • Applications
    Finance
    • Comptabilité
    • Facturation
    • Notes de frais
    • Feuilles de calcul (BI)
    • Documents
    • Signature
    Ventes
    • CRM
    • Ventes
    • PdV Boutique
    • PdV Restaurant
    • Abonnements
    • Location
    Sites web
    • Site Web
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Chaîne d'approvisionnement
    • Inventaire
    • Fabrication
    • PLM
    • Achats
    • Maintenance
    • Qualité
    Ressources Humaines
    • Employés
    • Recrutement
    • Congés
    • Évaluations
    • Recommandations
    • Parc automobile
    Marketing
    • Marketing Social
    • E-mail Marketing
    • SMS Marketing
    • Événements
    • Marketing Automation
    • Sondages
    Services
    • Projet
    • Feuilles de temps
    • Services sur Site
    • Assistance
    • Planification
    • Rendez-vous
    Productivité
    • Discussion
    • Validations
    • Internet des Objets
    • VoIP
    • Connaissances
    • WhatsApp
    Applications tierces Odoo Studio Plateforme Cloud d'Odoo
  • Industries
    Commerce de détail
    • Librairie
    • Magasin de vêtements
    • Magasin de meubles
    • Épicerie
    • Quincaillerie
    • Magasin de jouets
    Food & Hospitality
    • Bar et Pub
    • Restaurant
    • Fast-food
    • Maison d’hôtes
    • Distributeur de boissons
    • Hôtel
    Immobilier
    • Agence immobilière
    • Cabinet d'architecture
    • Construction
    • Gestion immobilière
    • Jardinage
    • Association de copropriétaires
    Consultance
    • Cabinet d'expertise comptable
    • Partenaire Odoo
    • Agence Marketing
    • Cabinet d'avocats
    • Aquisition de talents
    • Audit & Certification
    Fabrication
    • Textile
    • Métal
    • Meubles
    • Alimentation
    • Brewery
    • Cadeaux d'entreprise
    Santé & Fitness
    • Club de sports
    • Opticien
    • Salle de fitness
    • Praticiens bien-être
    • Pharmacie
    • Salon de coiffure
    Trades
    • Bricoleur
    • Matériel informatique et support
    • Systèmes photovoltaïques
    • Cordonnier
    • Services de nettoyage
    • Services CVC
    Autres
    • Organisation à but non lucratif
    • Agence environnementale
    • Location de panneaux d'affichage
    • Photographie
    • Leasing de vélos
    • Revendeur de logiciel
    Browse all Industries
  • Communauté
    Apprenez
    • Tutoriels
    • Documentation
    • Certifications
    • Formation
    • Blog
    • Podcast
    Renforcer l'éducation
    • Programme éducatif
    • Business Game Scale-Up!
    • Rendez-nous visite
    Obtenir le logiciel
    • Téléchargement
    • Comparez les éditions
    • Versions
    Collaborer
    • Github
    • Forum
    • Événements
    • Traductions
    • Devenez partenaire
    • Services for Partners
    • Enregistrer votre cabinet comptable
    Nos Services
    • Trouver un partenaire
    • Trouver un comptable
    • Rencontrer un conseiller
    • Services de mise en œuvre
    • Références clients
    • Assistance
    • Mises à niveau
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Obtenir une démonstration
  • Tarification
  • Aide

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

  • CRM
  • e-Commerce
  • Comptabilité
  • Inventaire
  • PoS
  • Projet
  • MRP
All apps
Vous devez être inscrit pour interagir avec la communauté.
Toutes les publications Personnes Badges
Étiquettes (Voir toutl)
odoo accounting v14 pos v15
À propos de ce forum
Vous devez être inscrit pour interagir avec la communauté.
Toutes les publications Personnes Badges
Étiquettes (Voir toutl)
odoo accounting v14 pos v15
À propos de ce forum
Aide

Create Journal Entries whit code

S'inscrire

Recevez une notification lorsqu'il y a de l'activité sur ce poste

Cette question a été signalée
pythonodoo12
2 Réponses
7288 Vues
Avatar
Pamela Castaneda

Hello, could someone help me with the creation of journal entries?

I am creating a custom module and I want to create journal entries with a button, the problem I have is that if there is more than one line or product the values of my journal entries are always those of the first line or product, for example if I have 3 products 3 journal items are created but all take the same value which would be the first product.


this is my PY


    def action_entry(self):
for rec in self:
for line in rec.avg_landed_cost_lines:
debit = line.average_landed_cost
credit = line.average_landed_cost
move = {
'name': '/',
'journal_id': rec.journal_id.id,
'date': rec.fecha,
'ref': rec.name,

'line_ids': [(0, 0, {
'name': line.product_id.name or '/',
'debit': debit,
'account_id': line.product_id.property_account_expense_id.id,
'partner_id': rec.order_id.partner_id.id,
}), (0, 0, {
'name': line.product_id.name or '/',
'credit': credit,
'account_id': line.product_id.property_account_income_id.id,
'partner_id': rec.order_id.partner_id.id,
})]
}
move_id = line.env['account.move'].create(move)
move_id.post()
return rec.write({'state': 'progress', 'move_id': move_id.id})


thanks!

0
Avatar
Ignorer
Avatar
Malay Khamar (Serpent Consulting Services Pvt. Ltd.)
Meilleure réponse

Hi Pamela Castaneda,

Your line_ids is not updated. Please try this code. 

def action_entry(self):
for rec in self:
move = {
'name': '/',
'journal_id': rec.journal_id.id,
'date': rec.fecha,
'ref': rec.name,
}
line_ids = []
for line in rec.avg_landed_cost_lines:
debit = line.average_landed_cost
credit = line.average_landed_cost

line_ids += [(0, 0, {
'name': line.product_id.name or '/',
'debit': debit,
'account_id': line.product_id.property_account_expense_id.id,
'partner_id': rec.order_id.partner_id.id
}), (0, 0, {
'name': line.product_id.name or '/',
'credit': credit,
'account_id': line.product_id.property_account_income_id.id,
'partner_id': rec.order_id.partner_id.id
})
]
if line_ids:
move.update({'line_ids': line_ids})
move_id = line.env['account.move'].create(move)
move_id.post()
rec.write({'state': 'progress', 'move_id': move_id.id})
return True



Hope it will help you.

2
Avatar
Ignorer
Avatar
Onestone Software LLP
Meilleure réponse

Hi ,

You have not added the line product amount in you code just add line items amount field it will work . please refer the code below and re format the code.

def action_entry(self):
for rec in self:
for line in rec.avg_landed_cost_lines: 
 
move = {
'name': '/',
'journal_id': rec\\.journal_id\\.id,
\\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ 'date':\\ rec\\.fecha,
\\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ 'ref':\\ rec\\.name,

\\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ 'line_ids':\\ \\[\\(0,\\ 0,\\ \\{
\\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ 'name':\\ line\\.product_id\\.name\\ or\\ '/',
\\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ 'debit'_=\\ line\\.average_landed_cost 
\\ \\ \\ \\ \\ \\ 'credit'\\ =\\ line\\.average_landed_cost
\\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ 'account_id':\\ line\\.product_id\\.property_account_expense_id\\.id,
\\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ 'partner_id':\\ rec\\.order_id\\.partner_id\\.id,
\\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\}\\),\\ \\(0,\\ 0,\\ \\{
\\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ 'name':\\ line\\.product_id\\.name\\ or\\ '/',
\\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ 'debit'_=\\ line\\.average_landed_cost 
\\ \\ \\ \\ \\ \\ 'credit'\\ =\\ line\\.average_landed_cost
\\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ 'account_id':\\ line\\.product_id\\.property_account_income_id\\.id,
\\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ 'partner_id':\\ rec\\.order_id\\.partner_id\\.id,
\\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\}\\)\\]
\\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\}
\\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ move_id\\ =\\ line\\.env\\['account\\.move'\\]\\.create\\(move\\)
\\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ move_id\\.post\\(\\)
\\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ return\\ rec\\.write\\(\\{'state':\\ 'progress',\\ 'move_id':\\ move_id.id})

0
Avatar
Ignorer
Vous appréciez la discussion ? Ne vous contentez pas de lire, rejoignez-nous !

Créez un compte dès aujourd'hui pour profiter de fonctionnalités exclusives et échanger avec notre formidable communauté !

S'inscrire
Publications associées Réponses Vues Activité
Two many2many fields related to each other inside one model Résolu
python odoo12
Avatar
1
juin 22
9165
how to make invoice date field readonly false for administrator after validating invoice in odoo12?
python odoo12
Avatar
Avatar
1
sept. 21
3925
Update tax in invoice line
python odoo12
Avatar
0
août 21
95
How do I find Average Cost Function?
python odoo12
Avatar
0
juil. 21
172
How to make invoice date edit after validation only for admins in odoo 12?
python odoo12
Avatar
0
mai 21
2336
Communauté
  • Tutoriels
  • Documentation
  • Forum
Open Source
  • Téléchargement
  • Github
  • Runbot
  • Traductions
Services
  • Hébergement Odoo.sh
  • Assistance
  • Migration
  • Développements personnalisés
  • Éducation
  • Trouver un comptable
  • Trouver un partenaire
  • Devenez partenaire
À propos
  • Notre société
  • Actifs de la marque
  • Contactez-nous
  • Emplois
  • Événements
  • Podcast
  • Blog
  • Clients
  • Informations légales • Confidentialité
  • Sécurité.
الْعَرَبيّة 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 est une suite d'applications open source couvrant tous les besoins de votre entreprise : CRM, eCommerce, Comptabilité, Inventaire, Point de Vente, Gestion de Projet, etc.

Le positionnement unique d'Odoo est d'être à la fois très facile à utiliser et totalement intégré.

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