Skip to Content
Odoo Meniu
  • Autentificare
  • Try it free
  • Aplicații
    Finanțe
    • Contabilitate
    • Facturare
    • Cheltuieli
    • Spreadsheet (BI)
    • Documente
    • Semn
    Vânzări
    • CRM
    • Vânzări
    • POS Shop
    • POS Restaurant
    • Abonamente
    • Închiriere
    Site-uri web
    • Constructor de site-uri
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Lanț Aprovizionare
    • Inventar
    • Producție
    • PLM
    • Achiziție
    • Maintenance
    • Calitate
    Resurse Umane
    • Angajați
    • Recrutare
    • Time Off
    • Evaluări
    • Referințe
    • Flotă
    Marketing
    • Social Marketing
    • Marketing prin email
    • SMS Marketing
    • Evenimente
    • Automatizare marketing
    • Sondaje
    Servicii
    • Proiect
    • Foi de pontaj
    • Servicii de teren
    • Centru de asistență
    • Planificare
    • Programări
    Productivitate
    • Discuss
    • Aprobări
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Aplicații Terțe Odoo Studio Platforma Odoo Cloud
  • Industrii
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Managament
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Producție
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware and Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Comunitate
    Învăță
    • Tutorials
    • Documentație
    • Certificări
    • Instruire
    • Blog
    • Podcast
    Empower Education
    • Program Educațional
    • Scale Up! Business Game
    • Visit Odoo
    Obține Software-ul
    • Descărcare
    • Compară Edițiile
    • Lansări
    Colaborați
    • Github
    • Forum
    • Evenimente
    • Translations
    • Devino Partener
    • Services for Partners
    • Înregistrează-ți Firma de Contabilitate
    Obține Servicii
    • Găsește un Partener
    • Găsiți un contabil
    • Meet an advisor
    • Servicii de Implementare
    • Referințe ale clienților
    • Suport
    • Actualizări
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Obține un demo
  • Prețuri
  • Ajutor

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

  • CRM
  • e-Commerce
  • Contabilitate
  • Inventar
  • PoS
  • Proiect
  • MRP
All apps
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Suport

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

Abonare

Primiți o notificare când există activitate la acestă postare

Această întrebare a fost marcată
fields.many2oneunknownodoo16
1671 Vizualizări
Imagine profil
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
Imagine profil
Abandonează
Enjoying the discussion? Don't just read, join in!

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

Înscrie-te
Related Posts Răspunsuri Vizualizări Activitate
Automatic Batch Transfer Rezolvat
odoo16
Imagine profil
Imagine profil
1
aug. 25
1217
Automatic Batch Transfer
odoo16
Imagine profil
Imagine profil
1
mai 25
2025
Bank statement import via email
odoo16
Imagine profil
0
nov. 24
1989
Display 'total' ( Like in Sale Order) on TOP
odoo16
Imagine profil
Imagine profil
2
oct. 24
2068
I have a manufacturing type product that comes out with 0 stock despite having materials.
odoo16
Imagine profil
0
aug. 24
1627
Comunitate
  • Tutorials
  • Documentație
  • Forum
Open Source
  • Descărcare
  • Github
  • Runbot
  • Translations
Servicii
  • Hosting Odoo.sh
  • Suport
  • Actualizare
  • Custom Developments
  • Educație
  • Găsiți un contabil
  • Găsește un Partener
  • Devino Partener
Despre Noi
  • Compania noastră
  • Active de marcă
  • Contactați-ne
  • Locuri de muncă
  • Evenimente
  • Podcast
  • Blog
  • Clienți
  • Aspecte juridice • Confidențialitate
  • Securitate
الْعَرَبيّة 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 este o suită de aplicații de afaceri open source care acoperă toate nevoile companiei dvs.: CRM, comerț electronic, contabilitate, inventar, punct de vânzare, management de proiect etc.

Propunerea de valoare unică a Odoo este să fie în același timp foarte ușor de utilizat și complet integrat.

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