diff options
Diffstat (limited to 'indoteknik_custom/models/account_move_line.py')
| -rw-r--r-- | indoteknik_custom/models/account_move_line.py | 65 |
1 files changed, 64 insertions, 1 deletions
diff --git a/indoteknik_custom/models/account_move_line.py b/indoteknik_custom/models/account_move_line.py index 7c95d4ef..5edea25f 100644 --- a/indoteknik_custom/models/account_move_line.py +++ b/indoteknik_custom/models/account_move_line.py @@ -1,5 +1,5 @@ from odoo import models, api, fields - +from odoo.exceptions import AccessError, UserError, ValidationError class AccountMoveLine(models.Model): _inherit = "account.move.line" @@ -9,6 +9,69 @@ class AccountMoveLine(models.Model): analytic_account_ids = fields.Many2many('account.analytic.account', string='Analytic Account') line_no = fields.Integer('No', default=0) + def action_gl_reconcile(self): + lines = self + + journal = self.env['account.journal'].search([ + ('suspense_account_id', '=', lines[0].account_id.id) + ], limit=1) + + if not journal: + raise UserError('Journal dengan suspense account ini tidak ditemukan!') + + statement = self.env['account.bank.statement'].create({ + 'journal_id': journal.id, + 'name': f'REKONSIL {journal.name} {lines[0].date.strftime("%d-%m-%Y")}', + 'company_id': self.env.company.id, + 'date': lines[0].date, + }) + + widget_vals = [] + st_line_ids = [] + + for line in lines: + amount = line.debit - line.credit + + st_line = self.env['account.bank.statement.line'].create({ + 'statement_id': statement.id, + 'date': line.date or fields.Date.today(), + 'payment_ref': line.name, + 'partner_id': line.partner_id.id, + 'amount': amount, + 'ref': line.name, + }) + + st_line_ids.append(st_line.id) + + widget_vals.append({ + 'partner_id': st_line.partner_id.id, + 'counterpart_aml_dicts': [{ + 'counterpart_aml_id': line.id, + 'debit': abs(amount) if amount < 0 else 0, + 'credit': abs(amount) if amount > 0 else 0, + 'name': line.name or '/', + }], + 'payment_aml_ids': [], + 'new_aml_dicts': [], + 'to_check': False, + }) + + statement.button_post() + + self.env['account.reconciliation.widget'].process_bank_statement_line( + st_line_ids, + widget_vals + ) + # statement.button_validate_or_action() + + return { + 'effect': { + 'fadeout': 'slow', + 'message': 'Statement + Auto Reconcile sukses besar 😎🔥', + 'type': 'rainbow_man', + } + } + @api.onchange('account_id') def _onchange_account_id(self): for account in self: |
