feat: add RK payment journal support to account moves and update POS mirror session partner alignment
This commit is contained in:
parent
d61396fe9c
commit
964e180fea
@ -1,10 +1,59 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from odoo import models, api, fields, _
|
||||
from odoo.exceptions import UserError
|
||||
from odoo.exceptions import UserError, ValidationError
|
||||
|
||||
class AccountMove(models.Model):
|
||||
_inherit = 'account.move'
|
||||
|
||||
rk_payment_journal_id = fields.Many2one(
|
||||
'account.journal',
|
||||
string='RK Payment Journal',
|
||||
help='The bank/cash journal used for this Hubungan RK process'
|
||||
)
|
||||
|
||||
def _get_last_sequence(self, relaxed=False, with_prefix=None):
|
||||
self.ensure_one()
|
||||
if not self.rk_payment_journal_id:
|
||||
return super()._get_last_sequence(relaxed=relaxed, with_prefix=with_prefix)
|
||||
|
||||
if self._sequence_field not in self._fields or not self._fields[self._sequence_field].store:
|
||||
raise ValidationError(_('%s is not a stored field', self._sequence_field))
|
||||
|
||||
where_string, param = self._get_last_sequence_domain(relaxed)
|
||||
if self._origin.id:
|
||||
where_string += " AND id != %(id)s "
|
||||
param['id'] = self._origin.id
|
||||
|
||||
prefix_base = f"{self.journal_id.code}-{self.rk_payment_journal_id.code}"
|
||||
|
||||
if with_prefix is not None:
|
||||
where_string += " AND sequence_prefix = %(with_prefix)s "
|
||||
param['with_prefix'] = with_prefix
|
||||
else:
|
||||
where_string += " AND sequence_prefix LIKE %(prefix_like)s "
|
||||
param['prefix_like'] = f"{prefix_base}/%"
|
||||
|
||||
query = f"""
|
||||
SELECT {self._sequence_field} FROM {self._table}
|
||||
{where_string}
|
||||
AND sequence_prefix = (SELECT sequence_prefix FROM {self._table} {where_string} ORDER BY id DESC LIMIT 1)
|
||||
ORDER BY sequence_number DESC
|
||||
LIMIT 1
|
||||
"""
|
||||
|
||||
self.flush_model([self._sequence_field, 'sequence_number', 'sequence_prefix'])
|
||||
self.env.cr.execute(query, param)
|
||||
return (self.env.cr.fetchone() or [None])[0]
|
||||
|
||||
def _get_starting_sequence(self):
|
||||
self.ensure_one()
|
||||
if self.rk_payment_journal_id:
|
||||
move_date = self.date or self.invoice_date or fields.Date.context_today(self)
|
||||
year_part = "%04d" % move_date.year
|
||||
prefix_base = f"{self.journal_id.code}-{self.rk_payment_journal_id.code}"
|
||||
return f"{prefix_base}/{year_part}/{move_date.month:02d}/0000"
|
||||
return super()._get_starting_sequence()
|
||||
|
||||
def action_post(self):
|
||||
res = super().action_post()
|
||||
|
||||
@ -53,6 +102,7 @@ class AccountMove(models.Model):
|
||||
'date': payment.date,
|
||||
'company_id': parent_company.id,
|
||||
'journal_id': parent_journal.id,
|
||||
'partner_id': payment.company_id.partner_id.id,
|
||||
'currency_id': parent_currency.id,
|
||||
'ref': f"Centralized Payment: {payment.name} ({payment.company_id.name})",
|
||||
'line_ids': [
|
||||
@ -61,7 +111,7 @@ class AccountMove(models.Model):
|
||||
'account_id': parent_rk_account.id,
|
||||
'debit': amount_parent_curr,
|
||||
'credit': 0.0,
|
||||
'partner_id': payment.partner_id.id,
|
||||
'partner_id': payment.company_id.partner_id.id,
|
||||
'company_id': parent_company.id,
|
||||
'currency_id': payment.currency_id.id,
|
||||
'amount_currency': payment.amount,
|
||||
@ -72,7 +122,7 @@ class AccountMove(models.Model):
|
||||
'account_id': parent_journal_sudo.default_account_id.id,
|
||||
'debit': 0.0,
|
||||
'credit': amount_parent_curr,
|
||||
'partner_id': payment.partner_id.id,
|
||||
'partner_id': payment.company_id.partner_id.id,
|
||||
'company_id': parent_company.id,
|
||||
'currency_id': payment.currency_id.id,
|
||||
'amount_currency': -payment.amount,
|
||||
|
||||
@ -234,11 +234,12 @@ class PosSession(models.Model):
|
||||
_logger.warning("No outstanding receipt account found on parent bank journal %s. Skipping PM %s.", parent_bank_journal.name, pm.name)
|
||||
continue
|
||||
|
||||
group_key = (parent_company.id, parent_clearing_journal.id)
|
||||
group_key = (parent_company.id, parent_clearing_journal.id, parent_bank_journal.id)
|
||||
if group_key not in parent_groups:
|
||||
parent_groups[group_key] = {
|
||||
'parent_company': parent_company,
|
||||
'parent_clearing_journal': parent_clearing_journal,
|
||||
'parent_bank_journal': parent_bank_journal,
|
||||
'lines_data': []
|
||||
}
|
||||
|
||||
@ -255,6 +256,7 @@ class PosSession(models.Model):
|
||||
for group_key, group_data in parent_groups.items():
|
||||
parent_company = group_data['parent_company']
|
||||
parent_clearing_journal = group_data['parent_clearing_journal']
|
||||
parent_bank_journal = group_data['parent_bank_journal']
|
||||
|
||||
line_ids = []
|
||||
|
||||
@ -275,6 +277,7 @@ class PosSession(models.Model):
|
||||
'account_id': line_data['outstanding_receipt_account'].id,
|
||||
'debit': amount_parent_curr,
|
||||
'credit': 0.0,
|
||||
'partner_id': session.company_id.partner_id.id,
|
||||
'currency_id': session.currency_id.id,
|
||||
'amount_currency': amount,
|
||||
}))
|
||||
@ -284,6 +287,7 @@ class PosSession(models.Model):
|
||||
'account_id': line_data['parent_rk_account'].id,
|
||||
'debit': 0.0,
|
||||
'credit': amount_parent_curr,
|
||||
'partner_id': session.company_id.partner_id.id,
|
||||
'currency_id': session.currency_id.id,
|
||||
'amount_currency': -amount,
|
||||
}))
|
||||
@ -297,6 +301,8 @@ class PosSession(models.Model):
|
||||
'ref': f"POS Mirror: {session.name} - {session.company_id.name}",
|
||||
'move_type': 'entry',
|
||||
'company_id': parent_company.id,
|
||||
'partner_id': session.company_id.partner_id.id,
|
||||
'rk_payment_journal_id': parent_bank_journal.id,
|
||||
'line_ids': line_ids,
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user