from odoo import fields, models, api from odoo.tools.misc import format_date, OrderedSet from odoo.exceptions import UserError class AccountPayment(models.Model): _inherit = 'account.payment' def action_multi_reset_to_draft(self): for payment in self: if payment.state != 'posted': raise UserError("Only posted payments can be reset to draft.") payment.action_draft() @api.constrains('journal_id') def set_default_journal_id(self): for rec in self: rec.journal_id = 21 def auto_sync_payment(self): for payment in self: if not payment.ref: continue # bill_names = payment.ref.split() bill_names = [x.strip() for x in payment.ref.split() if x.strip()] move_line = self.env['account.move.line'].search([ ('move_id', '=', payment.move_id.id), ('account_id', '=', 388), ]) for bill_name in bill_names: bill = self.env['account.move'].search([ ('name', '=', bill_name), ('move_type', '=', 'in_invoice'), ('state', '=', 'posted'), ('payment_state', '=', 'not_paid'), ], limit=1) if not bill: continue if move_line: bill.js_assign_outstanding_line(move_line.id)