mirror of
https://github.com/bringout/oca-ocb-accounting.git
synced 2026-04-22 04:42:01 +02:00
19.0 vanilla
This commit is contained in:
parent
ba20ce7443
commit
768b70e05e
2357 changed files with 1057103 additions and 712486 deletions
|
|
@ -1,15 +1,14 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from odoo import api, fields, models, _
|
||||
from odoo.exceptions import UserError
|
||||
from odoo.tools.date_utils import get_month, get_fiscal_year
|
||||
from odoo.tools.date_utils import get_fiscal_year
|
||||
from odoo.tools.misc import format_date
|
||||
|
||||
import re
|
||||
from collections import defaultdict
|
||||
import json
|
||||
|
||||
|
||||
class ReSequenceWizard(models.TransientModel):
|
||||
class AccountResequenceWizard(models.TransientModel):
|
||||
_name = 'account.resequence.wizard'
|
||||
_description = 'Remake the sequence of Journal Entries.'
|
||||
|
||||
|
|
@ -23,9 +22,9 @@ class ReSequenceWizard(models.TransientModel):
|
|||
preview_moves = fields.Text(compute='_compute_preview_moves')
|
||||
|
||||
@api.model
|
||||
def default_get(self, fields_list):
|
||||
values = super(ReSequenceWizard, self).default_get(fields_list)
|
||||
if 'move_ids' not in fields_list:
|
||||
def default_get(self, fields):
|
||||
values = super().default_get(fields)
|
||||
if 'move_ids' not in fields:
|
||||
return values
|
||||
active_move_ids = self.env['account.move']
|
||||
if self.env.context['active_model'] == 'account.move' and 'active_ids' in self.env.context:
|
||||
|
|
@ -39,7 +38,7 @@ class ReSequenceWizard(models.TransientModel):
|
|||
and len(move_types) > 1
|
||||
):
|
||||
raise UserError(_('The sequences of this journal are different for Invoices and Refunds but you selected some of both types.'))
|
||||
is_payment = set(active_move_ids.mapped(lambda x: bool(x.payment_id)))
|
||||
is_payment = set(active_move_ids.mapped(lambda x: bool(x.origin_payment_id)))
|
||||
if (
|
||||
active_move_ids.journal_id.payment_sequence
|
||||
and len(is_payment) > 1
|
||||
|
|
@ -74,7 +73,13 @@ class ReSequenceWizard(models.TransientModel):
|
|||
or (self.sequence_number_reset == 'year_range' and line['server-year-start-date'][0:4] != previous_line['server-year-start-date'][0:4])\
|
||||
or (self.sequence_number_reset == 'month' and line['server-date'][0:7] != previous_line['server-date'][0:7]):
|
||||
if in_elipsis:
|
||||
changeLines.append({'id': 'other_' + str(line['id']), 'current_name': _('... (%s other)', in_elipsis), 'new_by_name': '...', 'new_by_date': '...', 'date': '...'})
|
||||
changeLines.append({
|
||||
'id': 'other_' + str(line['id']),
|
||||
'current_name': _('... (%(nb_of_values)s other)', nb_of_values=in_elipsis),
|
||||
'new_by_name': '...',
|
||||
'new_by_date': '...',
|
||||
'date': '...',
|
||||
})
|
||||
in_elipsis = 0
|
||||
changeLines.append(line)
|
||||
else:
|
||||
|
|
@ -91,16 +96,18 @@ class ReSequenceWizard(models.TransientModel):
|
|||
"""Compute the proposed new values.
|
||||
|
||||
Sets a json string on new_values representing a dictionary thats maps account.move
|
||||
ids to a disctionay containing the name if we execute the action, and information
|
||||
ids to a dictionary containing the name if we execute the action, and information
|
||||
relative to the preview widget.
|
||||
"""
|
||||
def _get_move_key(move_id):
|
||||
company = move_id.company_id
|
||||
year_start, year_end = get_fiscal_year(move_id.date, day=company.fiscalyear_last_day, month=int(company.fiscalyear_last_month))
|
||||
date_start, date_end = get_fiscal_year(move_id.date, day=company.fiscalyear_last_day, month=int(company.fiscalyear_last_month))
|
||||
if self.sequence_number_reset == 'year':
|
||||
return move_id.date.year
|
||||
elif self.sequence_number_reset == 'year_range':
|
||||
return "%s-%s"%(year_start.year, year_end.year)
|
||||
return "%s-%s" % (date_start.year, date_end.year)
|
||||
elif self.sequence_number_reset == 'year_range_month':
|
||||
return "%s-%s/%s" % (date_start.year, date_end.year, move_id.date.month)
|
||||
elif self.sequence_number_reset == 'month':
|
||||
return (move_id.date.year, move_id.date.month)
|
||||
return 'default'
|
||||
|
|
@ -117,7 +124,7 @@ class ReSequenceWizard(models.TransientModel):
|
|||
new_values = {}
|
||||
for j, period_recs in enumerate(moves_by_period.values()):
|
||||
# compute the new values period by period
|
||||
year_start, year_end = period_recs[0]._get_sequence_date_range(sequence_number_reset)
|
||||
date_start, date_end, forced_year_start, forced_year_end = period_recs[0]._get_sequence_date_range(sequence_number_reset)
|
||||
for move in period_recs:
|
||||
new_values[move.id] = {
|
||||
'id': move.id,
|
||||
|
|
@ -125,15 +132,15 @@ class ReSequenceWizard(models.TransientModel):
|
|||
'state': move.state,
|
||||
'date': format_date(self.env, move.date),
|
||||
'server-date': str(move.date),
|
||||
'server-year-start-date': str(year_start),
|
||||
'server-year-start-date': str(date_start),
|
||||
}
|
||||
|
||||
new_name_list = [seq_format.format(**{
|
||||
**format_values,
|
||||
'month': year_start.month,
|
||||
'year_end': year_end.year % (10 ** format_values['year_end_length']),
|
||||
'year': year_start.year % (10 ** format_values['year_length']),
|
||||
'seq': i + (format_values['seq'] if j == (len(moves_by_period)-1) else 1),
|
||||
'month': date_start.month,
|
||||
'year_end': (forced_year_end or date_end.year) % (10 ** format_values['year_end_length']),
|
||||
'year': (forced_year_start or date_start.year) % (10 ** format_values['year_length']),
|
||||
'seq': i + (format_values['seq'] if j == (len(moves_by_period) - 1) else 1),
|
||||
}) for i in range(len(period_recs))]
|
||||
|
||||
# For all the moves of this period, assign the name by increasing initial name
|
||||
|
|
@ -151,7 +158,7 @@ class ReSequenceWizard(models.TransientModel):
|
|||
if self.ordering == 'date':
|
||||
raise UserError(_('You can not reorder sequence by date when the journal is locked with a hash.'))
|
||||
moves_to_rename = self.env['account.move'].browse(int(k) for k in new_values.keys())
|
||||
moves_to_rename.name = '/'
|
||||
moves_to_rename.name = False
|
||||
moves_to_rename.flush_recordset(["name"])
|
||||
# If the db is not forcibly updated, the temporary renaming could only happen in cache and still trigger the constraint
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue