Skip to Content
Odoo Menu
  • Sign in
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Approvals
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    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 Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & 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
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help

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

  • CRM
  • e-Commerce
  • Accounting
  • Inventory
  • PoS
  • Project
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
Help

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

Subscribe

Get notified when there's activity on this post

This question has been flagged
accountingpaymentinvoicingdefault_getodoo13
4 Replies
9975 Views
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
Discard
Avatar
Cybrosys Techno Solutions Pvt.Ltd
Best Answer

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
Discard
Avatar
limon SR
Best Answer

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
Discard
Avatar
Nikul Chaudhary
Best Answer

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
Discard
Avatar
Pankaj Goyani
Best Answer

@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
Discard
Enjoying the discussion? Don't just read, join in!

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

Sign up
Related Posts Replies Views Activity
Transfer Debit Between Customers
accounting payment invoicing debit
Avatar
0
Mar 21
2649
Analytic Accounting in v17 Solved
accounting invoicing
Avatar
Avatar
Avatar
Avatar
3
Jul 25
3974
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
Mar 25
2394
Cannot post invoice with any invoice date set in January 2024 Solved
accounting invoicing
Avatar
Avatar
1
Sep 25
2467
Comment savoir qu'une commande est entièrement facturée ? Solved
accounting invoicing
Avatar
Avatar
1
Feb 25
2101
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة 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 a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

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