mirror of
https://github.com/bringout/oca-ocb-accounting.git
synced 2026-04-22 16:02:00 +02:00
19.0 vanilla
This commit is contained in:
parent
ba20ce7443
commit
768b70e05e
2357 changed files with 1057103 additions and 712486 deletions
|
|
@ -7,7 +7,7 @@ from odoo import _, api, fields, models
|
|||
from odoo.exceptions import ValidationError
|
||||
|
||||
|
||||
class FinancialYearOpeningWizard(models.TransientModel):
|
||||
class AccountFinancialYearOp(models.TransientModel):
|
||||
_name = 'account.financial.year.op'
|
||||
_description = 'Opening Balance of Financial Year'
|
||||
|
||||
|
|
@ -35,37 +35,65 @@ class FinancialYearOpeningWizard(models.TransientModel):
|
|||
date(2020, int(wiz.fiscalyear_last_month), wiz.fiscalyear_last_day)
|
||||
except ValueError:
|
||||
raise ValidationError(
|
||||
_('Incorrect fiscal year date: day is out of range for month. Month: %s; Day: %s') %
|
||||
(wiz.fiscalyear_last_month, wiz.fiscalyear_last_day)
|
||||
_('Incorrect fiscal year date: day is out of range for month. Month: %(month)s; Day: %(day)s',
|
||||
month=wiz.fiscalyear_last_month, day=wiz.fiscalyear_last_day)
|
||||
)
|
||||
|
||||
def write(self, vals):
|
||||
@api.model
|
||||
def _company_fields_to_update(self):
|
||||
return {'fiscalyear_last_day', 'fiscalyear_last_month', 'opening_date'}
|
||||
|
||||
@api.model
|
||||
def _update_company(self, company_id, vals):
|
||||
# Amazing workaround: non-stored related fields on company are a BAD idea since the 3 fields
|
||||
# must follow the constraint '_check_fiscalyear_last_day'. The thing is, in case of related
|
||||
# fields, the inverse write is done one value at a time, and thus the constraint is verified
|
||||
# one value at a time... so it is likely to fail.
|
||||
for wiz in self:
|
||||
wiz.company_id.write({
|
||||
'fiscalyear_last_day': vals.get('fiscalyear_last_day') or wiz.company_id.fiscalyear_last_day,
|
||||
'fiscalyear_last_month': vals.get('fiscalyear_last_month') or wiz.company_id.fiscalyear_last_month,
|
||||
'account_opening_date': vals.get('opening_date') or wiz.company_id.account_opening_date,
|
||||
})
|
||||
wiz.company_id.account_opening_move_id.write({
|
||||
'date': fields.Date.from_string(vals.get('opening_date') or wiz.company_id.account_opening_date) - timedelta(days=1),
|
||||
company_fields_to_update = {k: k for k in self._company_fields_to_update()}
|
||||
company_fields_to_update['opening_date'] = 'account_opening_date'
|
||||
company_id.write({
|
||||
company_field: vals[wizard_field] for wizard_field, company_field in company_fields_to_update.items() if wizard_field in vals
|
||||
})
|
||||
opening_date = vals.get('opening_date', company_id.account_opening_date)
|
||||
opening_move = company_id.account_opening_move_id
|
||||
if opening_date and opening_move.state == 'draft':
|
||||
opening_move.write({
|
||||
'date': fields.Date.from_string(opening_date) - timedelta(days=1),
|
||||
})
|
||||
|
||||
vals.pop('opening_date', None)
|
||||
vals.pop('fiscalyear_last_day', None)
|
||||
vals.pop('fiscalyear_last_month', None)
|
||||
@api.model_create_multi
|
||||
def create(self, vals_list):
|
||||
for vals in vals_list:
|
||||
if 'company_id' in vals:
|
||||
company = self.env['res.company'].browse(vals['company_id'])
|
||||
self._update_company(company, vals)
|
||||
|
||||
# we need to keep opening_date in vals since it's a required field otherwise the wizard fails to be created
|
||||
for key in self._company_fields_to_update() - {'opening_date'}:
|
||||
vals.pop(key, None)
|
||||
|
||||
return super().create(vals_list)
|
||||
|
||||
def write(self, vals):
|
||||
for wiz in self:
|
||||
wiz._update_company(wiz.company_id, vals)
|
||||
|
||||
for key in self._company_fields_to_update():
|
||||
vals.pop(key, None)
|
||||
|
||||
return super().write(vals)
|
||||
|
||||
def action_save_onboarding_fiscal_year(self):
|
||||
self.env.company.sudo().set_onboarding_step_done('account_setup_fy_data_state')
|
||||
step_state = self.env['onboarding.onboarding.step'].with_company(self.company_id).action_validate_step('account.onboarding_onboarding_step_fiscal_year')
|
||||
# move the state to DONE to avoid an update in the web_read
|
||||
if step_state == 'JUST_DONE':
|
||||
self.env.ref('account.onboarding_onboarding_account_dashboard')._prepare_rendering_values()
|
||||
return {'type': 'ir.actions.client', 'tag': 'soft_reload'}
|
||||
|
||||
|
||||
class SetupBarBankConfigWizard(models.TransientModel):
|
||||
_inherits = {'res.partner.bank': 'res_partner_bank_id'}
|
||||
class AccountSetupBankManualConfig(models.TransientModel):
|
||||
_name = 'account.setup.bank.manual.config'
|
||||
_inherits = {'res.partner.bank': 'res_partner_bank_id'}
|
||||
_description = 'Bank setup manual config'
|
||||
_check_company_auto = True
|
||||
|
||||
|
|
@ -74,13 +102,19 @@ class SetupBarBankConfigWizard(models.TransientModel):
|
|||
linked_journal_id = fields.Many2one(string="Journal",
|
||||
comodel_name='account.journal', inverse='set_linked_journal_id',
|
||||
compute="_compute_linked_journal_id",
|
||||
domain=lambda self: [('type', '=', 'bank'), ('bank_account_id', '=', False), ('company_id', '=', self.env.company.id)])
|
||||
check_company=True,
|
||||
)
|
||||
bank_bic = fields.Char(related='bank_id.bic', readonly=False, string="Bic")
|
||||
num_journals_without_account = fields.Integer(default=lambda self: self._number_unlinked_journal())
|
||||
num_journals_without_account_bank = fields.Integer(default=lambda self: self._number_unlinked_journal('bank'))
|
||||
num_journals_without_account_credit = fields.Integer(default=lambda self: self._number_unlinked_journal('credit'))
|
||||
company_id = fields.Many2one('res.company', required=True, compute='_compute_company_id')
|
||||
|
||||
def _number_unlinked_journal(self):
|
||||
return self.env['account.journal'].search([('type', '=', 'bank'), ('bank_account_id', '=', False),
|
||||
('id', '!=', self.default_linked_journal_id())], count=True)
|
||||
def _number_unlinked_journal(self, journal_type):
|
||||
return self.env['account.journal'].search_count([
|
||||
('type', '=', journal_type),
|
||||
('bank_account_id', '=', False),
|
||||
('id', '!=', self.default_linked_journal_id(journal_type)),
|
||||
])
|
||||
|
||||
@api.onchange('acc_number')
|
||||
def _onchange_acc_number(self):
|
||||
|
|
@ -98,7 +132,7 @@ class SetupBarBankConfigWizard(models.TransientModel):
|
|||
vals['new_journal_name'] = vals['acc_number']
|
||||
|
||||
# If no bank has been selected, but we have a bic, we are using it to find or create the bank
|
||||
if not vals['bank_id'] and vals['bank_bic']:
|
||||
if not vals.get('bank_id') and vals.get('bank_bic'):
|
||||
vals['bank_id'] = self.env['res.bank'].search([('bic', '=', vals['bank_bic'])], limit=1).id \
|
||||
or self.env['res.bank'].create({'name': vals['bank_bic'], 'bic': vals['bank_bic']}).id
|
||||
|
||||
|
|
@ -112,38 +146,56 @@ class SetupBarBankConfigWizard(models.TransientModel):
|
|||
|
||||
@api.depends('journal_id') # Despite its name, journal_id is actually a One2many field
|
||||
def _compute_linked_journal_id(self):
|
||||
journal_type = self.env.context.get('journal_type', 'bank')
|
||||
for record in self:
|
||||
record.linked_journal_id = record.journal_id and record.journal_id[0] or record.default_linked_journal_id()
|
||||
record.linked_journal_id = record.journal_id and record.journal_id[0] or record.default_linked_journal_id(journal_type)
|
||||
|
||||
def default_linked_journal_id(self):
|
||||
for journal_id in self.env['account.journal'].search([('type', '=', 'bank'), ('bank_account_id', '=', False)]):
|
||||
empty_journal_count = self.env['account.move'].search_count([('journal_id', '=', journal_id.id)])
|
||||
if empty_journal_count == 0:
|
||||
return journal_id.id
|
||||
return False
|
||||
def default_linked_journal_id(self, journal_type):
|
||||
journals_with_moves = self.env['account.move'].search_fetch(
|
||||
[
|
||||
('journal_id', '!=', False),
|
||||
('journal_id.type', '=', journal_type),
|
||||
],
|
||||
['journal_id'],
|
||||
).journal_id
|
||||
|
||||
return self.env['account.journal'].search(
|
||||
[
|
||||
('type', '=', journal_type),
|
||||
('bank_account_id', '=', False),
|
||||
('id', 'not in', journals_with_moves.ids),
|
||||
],
|
||||
limit=1,
|
||||
).id
|
||||
|
||||
def set_linked_journal_id(self):
|
||||
""" Called when saving the wizard.
|
||||
"""
|
||||
journal_type = self.env.context.get('journal_type', 'bank')
|
||||
for record in self:
|
||||
selected_journal = record.linked_journal_id
|
||||
if not selected_journal:
|
||||
new_journal_code = self.env['account.journal'].get_next_bank_cash_default_code('bank', self.env.company)
|
||||
new_journal_code = self.env['account.journal']._get_next_journal_default_code(journal_type, self.env.company)
|
||||
company = self.env.company
|
||||
selected_journal = self.env['account.journal'].create({
|
||||
record.linked_journal_id = self.env['account.journal'].create({
|
||||
'name': record.new_journal_name,
|
||||
'code': new_journal_code,
|
||||
'type': 'bank',
|
||||
'type': journal_type,
|
||||
'company_id': company.id,
|
||||
'bank_account_id': record.res_partner_bank_id.id,
|
||||
'bank_statements_source': 'undefined',
|
||||
})
|
||||
else:
|
||||
selected_journal.bank_account_id = record.res_partner_bank_id.id
|
||||
selected_journal.name = record.new_journal_name
|
||||
|
||||
def validate(self):
|
||||
""" Called by the validation button of this wizard. Serves as an
|
||||
"""Called by the validation button of this wizard. Serves as an
|
||||
extension hook in account_bank_statement_import.
|
||||
"""
|
||||
self.linked_journal_id.mark_bank_setup_as_done_action()
|
||||
return {'type': 'ir.actions.client', 'tag': 'soft_reload'}
|
||||
|
||||
def _compute_company_id(self):
|
||||
for wizard in self:
|
||||
if not wizard.company_id:
|
||||
wizard.company_id = self.env.company
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue