1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
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'
@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)
|