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
    Restauration & Hôtellerie
    • 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
    • Brasserie
    • Cadeaux d'entreprise
    Santé & Fitness
    • Club de sports
    • Opticien
    • Salle de fitness
    • Praticiens bien-être
    • Pharmacie
    • Salon de coiffure
    Commerce
    • Bricoleur
    • Matériel informatique & 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
    Parcourir toutes les 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
    • Devenir partenaire
    • Services pour partenaires
    • 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
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

Journal Entry

S'inscrire

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

Cette question a été signalée
developmenttechnicalodoo16features
1 Répondre
3430 Vues
Avatar
klRZ

I have set Costing method as average cost and Inventory Valuation as Automated, I created a landed cost the cost changes and I changed the price manually and caused a Stock Valuation Layer and Journal entries has been created,

I want to delete these entries using code how?

0
Avatar
Ignorer
klRZ
Auteur

i created a button in landed cost to cancel i tried something like this so when i change the product price 2 entries are created one 'stock.valuation.layer' and one Journal entree

stock valuation contatins a description saying Product value manually modified from 1000 to 200

i tried it using like this

if product.cost_method == 'average':
original_price = product.standard_price
new_price = product.standard_price - line.additional_landed_cost
product.write({'standard_price': new_price})
stock_valuation_layer = self.env['stock.valuation.layer'] \
.search([('product_id', '=', product.id),
('description', '=', f'Product value manually '
f'modified (from {original_price} to {new_price})')],
limit=1)
if stock_valuation_layer:
stock_valuation_layer.account_move_id.button_draft()
stock_valuation_layer.account_move_id.sudo().unlink()
stock_valuation_layer.sudo().unlink()

 
This works but  i want to search that stock.valuation.layer instead of seaching using description ,any other way? for this 

self.env['stock.valuation.layer'] \
.search([('product_id', '=', product.id),
('description', '=', f'Product value manually '
f'modified (from {
original_price} to {new_price})')],
limit
=1) or should i keep it like this

ANY IDEAS  

Avatar
shubham shiroya
Meilleure réponse

you can achieve it using code. Here's an example of how you can delete these entries programmatically:

# Import necessary models
from odoo import api, models

class StockValuationEntryDeletion(models.Model):
_inherit = 'stock.valuation.layer'

@api.model
def delete_entries(self, product_id):
# Retrieve the Stock Valuation Layer entries for the given product
valuation_entries = self.search([('product_id', '=', product_id)])

# Delete the Stock Valuation Layer entries
valuation_entries.unlink()

class JournalEntryDeletion(models.Model):
_inherit = 'account.move'

@api.model
def delete_entries(self, product_id):
# Retrieve the Journal entries for the given product
journal_entries = self.env['account.move'].search([('stock_valuation_layer_ids.product_id', '=', product_id)])

# Delete the Journal entries
journal_entries.unlink()


You can then use these methods to delete the entries. For example:

product_id = 123 # Replace with the actual product ID
StockValuationEntryDeletion.delete_entries(product_id)
JournalEntryDeletion.delete_entries(product_id)

Make sure you run this code with the necessary access rights and proper validation to ensure the correct entries are deleted. It's recommended to test this code in a development environment first and take proper backups before running it in a production environment.


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é
Odoo Server Error when opening Hospital Module?
development odoo16features
Avatar
Avatar
1
sept. 23
3538
how to populate a new field in odoo on old records
development fields odoo16features
Avatar
Avatar
1
août 25
4246
What are the fields ending with "_signed" in the model account_move for? Résolu
development invoicing odoo16features
Avatar
Avatar
1
avr. 24
4187
Can i Integrate Erply POS website to Odoo Enterprise 16.3 online (Saas) .. ??
development implementation odoo16features
Avatar
0
oct. 23
3256
Why I can't see my Custom Model in Apps? Résolu
development documentation odoo16features
Avatar
Avatar
Avatar
2
sept. 23
4988
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
  • Devenir 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 Svenska ภาษาไทย 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