Overslaan naar inhoud
Odoo Menu
  • Aanmelden
  • Probeer het gratis
  • Apps
    Financiën
    • Boekhouding
    • Facturatie
    • Onkosten
    • Spreadsheet (BI)
    • Documenten
    • Ondertekenen
    Verkoop
    • CRM
    • Verkoop
    • Kassasysteem winkel
    • Kassasysteem Restaurant
    • Abonnementen
    • Verhuur
    Websites
    • Websitebouwer
    • E-commerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Bevoorradingsketen
    • Voorraad
    • Productie
    • PLM
    • Inkoop
    • Onderhoud
    • Kwaliteit
    Personeelsbeheer
    • Werknemers
    • Werving & Selectie
    • Verlof
    • Evaluaties
    • Aanbevelingen
    • Wagenpark
    Marketing
    • Sociale media-marketing
    • E-mailmarketing
    • Sms-marketing
    • Evenementen
    • Marketingautomatisering
    • Enquêtes
    Diensten
    • Project
    • Urenstaten
    • Buitendienst
    • Helpdesk
    • Planning
    • Afspraken
    Productiviteit
    • Chat
    • Goedkeuringen
    • IoT
    • VoIP
    • Kennis
    • WhatsApp
    Apps van derden Odoo Studio Odoo Cloud Platform
  • Bedrijfstakken
    Detailhandel
    • Boekhandel
    • kledingwinkel
    • Meubelzaak
    • Supermarkt
    • Bouwmarkt
    • Speelgoedwinkel
    Food & Hospitality
    • Bar en Pub
    • Restaurant
    • Fastfood
    • Gastenverblijf
    • Drankenhandelaar
    • Hotel
    Vastgoed
    • Makelaarskantoor
    • Architectenbureau
    • Bouw
    • Vastgoedbeheer
    • Tuinieren
    • Vereniging van eigenaren
    Consulting
    • Accountantskantoor
    • Odoo Partner
    • Marketingbureau
    • Advocatenkantoor
    • Talentenwerving
    • Audit & Certificering
    Productie
    • Textiel
    • Metaal
    • Meubels
    • Eten
    • Brewery
    • Relatiegeschenken
    Gezondheid & Fitness
    • Sportclub
    • Opticien
    • Fitnesscentrum
    • Wellness-medewerkers
    • Apotheek
    • Kapper
    Trades
    • Klusjesman
    • IT-hardware & support
    • Zonne-energiesystemen
    • Schoenmaker
    • Schoonmaakdiensten
    • HVAC-diensten
    Andere
    • Non-profitorganisatie
    • Milieuagentschap
    • Verhuur van Billboards
    • Fotograaf
    • Fietsleasing
    • Softwareverkoper
    Browse all Industries
  • Community
    Leren
    • Tutorials
    • Documentatie
    • Certificeringen
    • Training
    • Blog
    • Podcast
    Versterk het onderwijs
    • Onderwijs- programma
    • Scale Up! Business Game
    • Bezoek Odoo
    Download de Software
    • Downloaden
    • Vergelijk edities
    • Releases
    Werk samen
    • Github
    • Forum
    • Evenementen
    • Vertalingen
    • Word een Partner
    • Services for Partners
    • Registreer je accountantskantoor
    Diensten
    • Vind een partner
    • Vind een boekhouder
    • Een adviseur ontmoeten
    • Implementatiediensten
    • Klantreferenties
    • Ondersteuning
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Vraag een demo aan
  • Prijzen
  • Help

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

  • CRM
  • e-Commerce
  • Boekhouding
  • Voorraad
  • PoS
  • Project
  • MRP
All apps
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Alle posts Personen Badges
Labels (Bekijk alle)
odoo accounting v14 pos v15
Over dit forum
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Alle posts Personen Badges
Labels (Bekijk alle)
odoo accounting v14 pos v15
Over dit forum
Help

How can I override the default_get method in account.payment?

Inschrijven

Ontvang een bericht wanneer er activiteit is op deze post

Deze vraag is gerapporteerd
accountingpaymentinvoicingdefault_getodoo13
4 Antwoorden
9984 Weergaven
Avatar
Stephen

Hi,

I  need to override the default_get(self, default_fields) method in order to include a newly created state in the following warning in that function. How can I do that? Thanks in advance

if not invoices or any(invoice.state != 'posted' for invoice in invoices):
raise UserError(_("You can only register payments for open invoices"))

0
Avatar
Annuleer
Avatar
Cybrosys Techno Solutions Pvt.Ltd
Beste antwoord

Hi,

Try the following

from odoo import models, fields, api, _
from odoo.addons.account.models.account_payment import account_payment


class AccountPayment(models.Model):
_inherit = 'account.payment'


@api.model
def default_get(self, default_fields):
# You can write your modified lines of code here
rec = super(account_payment, self).default_get(default_fields)
return rec


account_payment.default_get = default_get

Regards

4
Avatar
Annuleer
Avatar
limon SR
Beste antwoord

Hello, I had the same problem yet this solution is not working 

here is my code 

I can't get to the print inside the if active_model == 'sale.order' 


class AccountPaymentNumidoo(models.Model):
_inherit = "account.payment"
# order_line_ids = fields.One2many('sale.order.line', 'payment_id', readonly=True, copy=False, ondelete='restrict')
order_ids = fields.Many2many('sale.order', 'account_order_payment_rel', 'payment_id', 'order_id',
string="Invoices", copy=False, readonly=True,
help="""Technical field containing the invoice for which the payment has been generated.
This does not especially correspond to the invoices reconciled with the payment,
as it can have been generated first, and reconciled later""")
mode_payment = fields.Selection([('especes', 'Espèces'),
('par_cheque', 'Par chèque'),
('virement_bancaire', 'Virement Bancaire'),
('versement', 'Versement Bancaire'),
('traite', 'Traite')])
@api.model
def default_get(self, default_fields):
rec = super(account_payment, self).default_get(default_fields)
active_ids = self._context.get('active_ids') or self._context.get('active_id')
active_model = self._context.get('active_model')
print(active_model)
# Check for selected invoices ids
if not active_ids or active_model != 'account.move' or active_model != 'sale.order':
return rec
if active_model == 'account.move':
invoices = self.env['account.move'].browse(active_ids).filtered(lambda move: move.is_invoice(include_receipts=True))
# Check all invoices are open
if not invoices or any(invoice.state != 'posted' for invoice in invoices):
raise UserError(_("You can only register payments for open invoices"))
# Check if, in batch payments, there are not negative invoices and positive invoices
dtype = invoices[0].type
for inv in invoices[1:]:
if inv.type != dtype:
if ((dtype == 'in_refund' and inv.type == 'in_invoice') or
(dtype == 'in_invoice' and inv.type == 'in_refund')):
raise UserError(
_("You cannot register payments for vendor bills and supplier refunds at the same time."))
if ((dtype == 'out_refund' and inv.type == 'out_invoice') or
(dtype == 'out_invoice' and inv.type == 'out_refund')):
raise UserError(
_("You cannot register payments for customer invoices and credit notes at the same time."))

amount = self._compute_payment_amount(invoices, invoices[0].currency_id, invoices[0].journal_id,
rec.get('payment_date') or fields.Date.today())
rec.update({
'currency_id': invoices[0].currency_id.id,
'amount': abs(amount),
'payment_type': 'inbound' if amount > 0 else 'outbound',
'partner_id': invoices[0].commercial_partner_id.id,
'partner_type': MAP_INVOICE_TYPE_PARTNER_TYPE[invoices[0].type],
'communication': invoices[0].invoice_payment_ref or invoices[0].ref or invoices[0].name,
'invoice_ids': [(6, 0, invoices.ids)],
})
else:
if active_model == 'sale.order':
print("i aaaaaaaaaaaa ma sale order")
orders = self.env['sale.order'].browse(active_ids).filtered(lambda move: move.is_sale_document(include_receipts=True))
amount=0
rec.update({
'currency_id': orders[0].currency_id.id,
'amount': abs(amount),
'payment_type': 'inbound',
'partner_id': orders[0].commercial_partner_id.id,
#'partner_type': MAP_INVOICE_TYPE_PARTNER_TYPE[invoices[0].type],
'communication': orders[0].order_payment_ref or orders[0].ref or orders[0].name,
'order_ids': [(6, 0, order.ids)],
})
return rec
account_payment.default_get = default_get
0
Avatar
Annuleer
Avatar
Nikul Chaudhary
Beste antwoord

Hello Stephen
Please check below example, I think it's helpful for you.

Ex.
@api.model
    def default_get(self, default_fields):
        rec = super(Order, self).default_get(default_fields)
        active_model = self.env.context.get('active_model', False)
        active_id = self.env.context.get('active_id', False)
        if active_model and active_id and active_model == 'sale.order':
            invoices = self.env['sale.order'].browse(active_id).invoice_ids
            if not invoices or any(invoice.state != 'posted' for invoice in invoices):
                raise UserError(_("You can only register payments for open invoices"))

0
Avatar
Annuleer
Avatar
Pankaj Goyani
Beste antwoord

@api.model
def default_get(self, default_fields):
    res = super(AccountPayment, self).default_get(default_fields)
    active_ids = self._context.get('active_ids')
    invoices = self.env['account.invoice'].browse(active_ids)
    communication = ' '.join([ref for ref in invoices.mapped('reference') if ref]),
    res.update({
       'communication': communication,
    })
    return res

0
Avatar
Annuleer
Geniet je van het gesprek? Blijf niet alleen lezen, doe ook mee!

Maak vandaag nog een account aan om te profiteren van exclusieve functies en deel uit te maken van onze geweldige community!

Aanmelden
Gerelateerde posts Antwoorden Weergaven Activiteit
Transfer Debit Between Customers
accounting payment invoicing debit
Avatar
0
mrt. 21
2659
Analytic Accounting in v17 Opgelost
accounting invoicing
Avatar
Avatar
Avatar
Avatar
3
jul. 25
3977
Journal Entry PB-Tab/2025/00007 is not valid. In order to proceed, the journal items must include one and only one outstanding payments/receipts account.
accounting invoicing
Avatar
Avatar
1
mrt. 25
2401
Cannot post invoice with any invoice date set in January 2024 Opgelost
accounting invoicing
Avatar
Avatar
1
sep. 25
2469
Comment savoir qu'une commande est entièrement facturée ? Opgelost
accounting invoicing
Avatar
Avatar
1
feb. 25
2101
Community
  • Tutorials
  • Documentatie
  • Forum
Open Source
  • Downloaden
  • Github
  • Runbot
  • Vertalingen
Diensten
  • Odoo.sh Hosting
  • Ondersteuning
  • Upgrade
  • Gepersonaliseerde ontwikkelingen
  • Onderwijs
  • Vind een boekhouder
  • Vind een partner
  • Word een Partner
Over ons
  • Ons bedrijf
  • Merkelementen
  • Neem contact met ons op
  • Vacatures
  • Evenementen
  • Podcast
  • Blog
  • Klanten
  • Juridisch • Privacy
  • Beveiliging
الْعَرَبيّة 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 is een suite van open source zakelijke apps die aan al je bedrijfsbehoeften voldoet: CRM, E-commerce, boekhouding, inventaris, kassasysteem, projectbeheer, enz.

Odoo's unieke waardepropositie is om tegelijkertijd zeer gebruiksvriendelijk en volledig geïntegreerd te zijn.

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