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
    • Guest House
    • Distributeur de boissons
    • Hotel
    Real Estate
    • Real Estate Agency
    • Cabinet d'architecture
    • Construction
    • Gestion immobilière
    • Jardinage
    • Association de copropriétaires
    Consulting
    • Accounting Firm
    • Partenaire Odoo
    • Agence Marketing
    • Cabinet d'avocats
    • Aquisition de talents
    • Audit & Certification
    Fabrication
    • Textile
    • Metal
    • Furnitures
    • Food
    • 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
    • Solar Energy Systems
    • Cordonnier
    • Services de nettoyage
    • HVAC Services
    Others
    • Nonprofit Organization
    • 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

Problem with Linking Models in Odoo and Handling _unknown Value "self.id" giving _unknown(actual_id,)

S'inscrire

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

Cette question a été signalée
fields.many2oneunknownodoo16
1667 Vues
Avatar
Yaya

I'm working with Odoo 16 and have encountered a problem with linking two models and handling _unknown values. Specifically, I have two models: nkap_custom_paiement and account.payment.register. The former is a custom model inheriting from account.payment, and the latter is a TransientModel used for payment registration.

Models Overview: nkap_custom_paiement (Inheriting account.payment)

Has a field related_payment_id that links to account.register.payment. Handles payment approvals and has methods like action_cashier_approval to perform actions on linked payments. CustomPaymentRegister (Inheriting account.payment.register)

Handles the creation of account.payment records and sets the related_payment_id to link back to the wizard.

I am trying to add an approval process to the payment that are register throught the wizard then after the approval it should called back the initial method on the wizard(thats why i need to store id)

# -*- coding: utf-8 -*-

from odoo import models, fields, api, _
from odoo.exceptions import ValidationError, UserError
import re


class nkap_custom_paiement(models.Model):
    # _inherit = 'account.payment'
    _inherit = ['account.payment']

    related_payment_id = fields.Many2one('account.register.payment', string='Related Wizard')
    state = fields.Selection([
            ('draft', 'Drafted'),
            ('waiting_approval', 'Waiting Approval'),
            ('approved', 'Approved'),
            ('rejected', 'Rejected'),
            ('posted', 'Posted'),
        ], string="Approval Status",default='draft')

    DFC_approver_sign = fields.Binary('DFC Signature')
    DG_approver_sign = fields.Binary('DG Signature')
    current_approval = fields.Selection([('1', '1'), ('2', '2'), ('3', '3')], string="Is Current Approver")

    
    def action_submit_for_approval(self):
        company_id=self.env.company
        self.write({'state': 'waiting_approval'})       
        message = "Vous avez un paiement pour la 1ere approbation"
        self.current_approval = '1'
        self.activity_schedule('purchase_order_approval.mail_activity_data_approval', user_id=company_id.po_third_approver_ids.id, note=message)
        self.env['bus.bus']._sendone(company_id.po_third_approver_ids.partner_id, 'simple_notification', {'title': _("Information"), 'message': message})


    def action_DFC_approval(self):
        company_id=self.env.company
        if self.env.user.id in company_id.po_third_approver_ids.ids:
        
            self.current_approval = '2'
            self.write({'state': 'waiting_approval'})
            self.DFC_approver_sign = self.env.user.user_signature
            message = "Vous avez un paiement pour la 2ere approbation "
            self.activity_schedule('purchase_order_approval.mail_activity_data_approval', user_id=company_id.po_DG_approver_ids.id, note=message)
        else:
            raise ValidationError(_("Seul %s peut approver !"% company_id.po_third_approver_ids.id ))

    def action_DG_approval(self):
        company_id=self.env.company
        if self.env.user.id in company_id.po_DG_approver_ids.ids:      

            self.write({'state': 'approved'})
            self.current_approval = '3'
            self.DG_approver_sign = self.env.user.user_signature
            message = "Vous avez un paiement pour la validation"
            self.activity_schedule('purchase_order_approval.mail_activity_data_approval', user_id=company_id.po_fourth_approver_ids.id, note=message)
        else:
            raise ValidationError(_("Seul %s peut approver !"% company_id.po_DG_approver_ids.id ))

    def action_cashier_approval(self):
        company_id=self.env.company
        if self.env.user.id in company_id.po_fourth_approver_ids.ids:
            self.write({'state': 'posted'})
           
            if self.related_payment_id:
                related_payment = self.env['account.payment.register'].browse(self.related_payment_id)
                
                if related_payment.exists():
                    # Call a method on the related payment record
                    related_payment.action_create_payments()
                else:
                    _logger.error("Related payment record with ID %s does not exist", self.related_payment_id.id)
        else:
            raise ValidationError(_("Seul %s peut approver !"% company_id.po_fourth_approver_ids.id ))
        
    def action_reject(self):
        company_id=self.env.company
        current_approver = None
        if self.current_approval =='1':
            current_approver=company_id.po_third_approver_ids
        elif self.current_approval =='2':
            current_approver=company_id.po_DG_approver_ids
        else:
            raise UserError(_(f"{self.current_approval},{type(self.current_approval)}"))
        if self.env.user.id in current_approver.ids:
            self.write({'state': 'rejected'})
   
        else:
            raise ValidationError(_("Seul %s peut refuser cette DA !" % current_approver.name))

    def rollback(self):
        '''to cancel all the signature already done to false'''
        self.write({
            'DFC_approver_sign': False,
            'DG_approver_sign': False,
            'current_approval': False,
        })
        
        
        

class CustomPaymentRegister(models.TransientModel):
    _inherit = 'account.payment.register'
    payment_id = fields.Many2one('account.payment', string='Created Payment')

    
    def _collect_payment_vals(self):
    
        payment_vals = {
                'amount': self.amount,
                'partner_id': self.partner_id.id,
                'journal_id': self.journal_id.id,
                'payment_method_line_id': self.payment_method_line_id.id,
                'date': self.payment_date,
                'currency_id': self.currency_id.id,
                'ref': self.communication,
                'partner_bank_id': self.partner_bank_id.id,
                'bank_reference': self.bank_reference,
                'cheque_reference': self.cheque_reference,
        
            }
        return payment_vals


    def action_submit_for_approval(self):
        payment_vals = self._collect_payment_vals()
        payment = self.env['account.payment'].create(payment_vals)
        self.payment_id = payment.id
        payment.related_payment_id = self.id

        
        # raise ValidationError(_(f"{self.id}// {payment.related_payment_id}//{number}"))
        # Call the approval flow for each payment created
        payment.action_submit_for_approval()

I have tried several ways to link the both model throught the fields payment_id in account.register.payment model and related_payment_id in account.payment but it still giving the "self_id" in this _unknow(actual_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é
Automatic Batch Transfer Résolu
odoo16
Avatar
Avatar
1
août 25
1214
Automatic Batch Transfer
odoo16
Avatar
Avatar
1
mai 25
2024
Bank statement import via email
odoo16
Avatar
0
nov. 24
1985
Display 'total' ( Like in Sale Order) on TOP
odoo16
Avatar
Avatar
2
oct. 24
2065
I have a manufacturing type product that comes out with 0 stock despite having materials.
odoo16
Avatar
0
août 24
1627
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