|
|
@ -21,7 +21,9 @@ class GeneralLedgerReport(models.AbstractModel): |
|
|
|
'name': account.name, |
|
|
|
'group_id': account.group_id.id, |
|
|
|
'currency_id': account.currency_id or False, |
|
|
|
'currency_name': account.currency_id.name} |
|
|
|
'currency_name': account.currency_id.name, |
|
|
|
'centralized': account.centralized |
|
|
|
} |
|
|
|
}) |
|
|
|
return accounts_data |
|
|
|
|
|
|
@ -213,6 +215,7 @@ class GeneralLedgerReport(models.AbstractModel): |
|
|
|
else: |
|
|
|
prt_id = gl['partner_id'][0] |
|
|
|
prt_name = gl['partner_id'][1] |
|
|
|
prt_name = prt_name._value |
|
|
|
if prt_id not in partners_ids: |
|
|
|
partners_ids.add(prt_id) |
|
|
|
partners_data.update({ |
|
|
@ -283,7 +286,7 @@ class GeneralLedgerReport(models.AbstractModel): |
|
|
|
move_line['partner_id'] else False, |
|
|
|
'partner_name': move_line['partner_id'][1] if |
|
|
|
move_line['partner_id'] else "", |
|
|
|
'ref': move_line['name'], |
|
|
|
'ref': '' if not move_line['ref'] else move_line['ref'], |
|
|
|
'tax_ids': move_line['tax_ids'], |
|
|
|
'debit': move_line['debit'], |
|
|
|
'credit': move_line['credit'], |
|
|
@ -366,7 +369,7 @@ class GeneralLedgerReport(models.AbstractModel): |
|
|
|
'id', 'name', 'date', 'move_id', 'journal_id', 'account_id', |
|
|
|
'partner_id', 'debit', 'credit', 'balance', 'currency_id', |
|
|
|
'full_reconcile_id', 'tax_ids', 'analytic_tag_ids', |
|
|
|
'amount_currency'] |
|
|
|
'amount_currency', 'ref'] |
|
|
|
move_lines = self.env['account.move.line'].search_read( |
|
|
|
domain=domain, |
|
|
|
fields=ml_fields) |
|
|
@ -403,23 +406,13 @@ class GeneralLedgerReport(models.AbstractModel): |
|
|
|
if not move_line['partner_id']: |
|
|
|
prt_id = 0 |
|
|
|
partner_name = 'Missing Partner' |
|
|
|
if gen_ld_data: |
|
|
|
if prt_id not in gen_ld_data[acc_id]: |
|
|
|
if prt_id not in partners_ids: |
|
|
|
partners_ids.append(prt_id) |
|
|
|
partners_data.update({ |
|
|
|
prt_id: {'id': prt_id, |
|
|
|
'name': partner_name} |
|
|
|
}) |
|
|
|
gen_ld_data = self._initialize_partner( |
|
|
|
gen_ld_data, acc_id, prt_id, foreign_currency |
|
|
|
) |
|
|
|
else: |
|
|
|
partners_ids.append(prt_id) |
|
|
|
partners_data.update({ |
|
|
|
prt_id: {'id': prt_id, |
|
|
|
'name': partner_name} |
|
|
|
}) |
|
|
|
partners_ids.append(prt_id) |
|
|
|
partners_data.update({ |
|
|
|
prt_id: {'id': prt_id, |
|
|
|
'name': partner_name} |
|
|
|
}) |
|
|
|
if prt_id not in gen_ld_data[acc_id]: |
|
|
|
|
|
|
|
gen_ld_data = self._initialize_partner( |
|
|
|
gen_ld_data, acc_id, prt_id, foreign_currency |
|
|
|
) |
|
|
@ -452,6 +445,13 @@ class GeneralLedgerReport(models.AbstractModel): |
|
|
|
return gen_ld_data, accounts_data, partners_data, journals_data, \ |
|
|
|
full_reconcile_data, taxes_data, tags_data |
|
|
|
|
|
|
|
@api.model |
|
|
|
def _recalculate_cumul_balance(self, move_lines, last_cumul_balance): |
|
|
|
for move_line in move_lines: |
|
|
|
move_line['balance'] += last_cumul_balance |
|
|
|
last_cumul_balance = move_line['balance'] |
|
|
|
return move_lines |
|
|
|
|
|
|
|
@api.model |
|
|
|
def _create_general_ledger(self, gen_led_data, accounts_data): |
|
|
|
general_ledger = [] |
|
|
@ -462,6 +462,7 @@ class GeneralLedgerReport(models.AbstractModel): |
|
|
|
'name': accounts_data[acc_id]['name'], |
|
|
|
'type': 'account', |
|
|
|
'currency_id': accounts_data[acc_id]['currency_id'], |
|
|
|
'centralized': accounts_data[acc_id]['centralized'], |
|
|
|
}) |
|
|
|
if not gen_led_data[acc_id]['partners']: |
|
|
|
move_lines = [] |
|
|
@ -471,6 +472,8 @@ class GeneralLedgerReport(models.AbstractModel): |
|
|
|
else: |
|
|
|
move_lines += [gen_led_data[acc_id][ml_id]] |
|
|
|
move_lines = sorted(move_lines, key=lambda k: (k['date'])) |
|
|
|
move_lines = self._recalculate_cumul_balance( |
|
|
|
move_lines, gen_led_data[acc_id]['init_bal']['balance']) |
|
|
|
account.update({'move_lines': move_lines}) |
|
|
|
else: |
|
|
|
list_partner = [] |
|
|
@ -489,6 +492,10 @@ class GeneralLedgerReport(models.AbstractModel): |
|
|
|
gen_led_data[acc_id][prt_id][ml_id]] |
|
|
|
move_lines = sorted(move_lines, |
|
|
|
key=lambda k: (k['date'])) |
|
|
|
move_lines = self._recalculate_cumul_balance( |
|
|
|
move_lines, |
|
|
|
gen_led_data[acc_id][prt_id]['init_bal'][ |
|
|
|
'balance']) |
|
|
|
partner.update({'move_lines': move_lines}) |
|
|
|
list_partner += [partner] |
|
|
|
account.update({'list_partner': list_partner}) |
|
|
@ -496,47 +503,65 @@ class GeneralLedgerReport(models.AbstractModel): |
|
|
|
return general_ledger |
|
|
|
|
|
|
|
@api.model |
|
|
|
def _get_centralized_ml(self, partners, date_to): |
|
|
|
def _calculate_centralization(self, centralized_ml, move_line, date_to): |
|
|
|
jnl_id = move_line['journal_id'] |
|
|
|
month = move_line['date'].month |
|
|
|
if jnl_id not in centralized_ml.keys(): |
|
|
|
centralized_ml[jnl_id] = {} |
|
|
|
if month not in centralized_ml[jnl_id].keys(): |
|
|
|
centralized_ml[jnl_id][month] = {} |
|
|
|
last_day_month = \ |
|
|
|
calendar.monthrange(move_line['date'].year, month) |
|
|
|
date = datetime.date( |
|
|
|
move_line['date'].year, |
|
|
|
month, |
|
|
|
last_day_month[1]) |
|
|
|
if date > date_to: |
|
|
|
date = date_to |
|
|
|
centralized_ml[jnl_id][month].update({ |
|
|
|
'journal_id': jnl_id, |
|
|
|
'ref': 'Centralized entries', |
|
|
|
'date': date, |
|
|
|
'debit': 0.0, |
|
|
|
'credit': 0.0, |
|
|
|
'balance': 0.0, |
|
|
|
'bal_curr': 0.0, |
|
|
|
'partner_id': False, |
|
|
|
'rec_id': 0, |
|
|
|
'entry_id': False, |
|
|
|
'tax_ids': [], |
|
|
|
'full_reconcile_id': False, |
|
|
|
'id': False, |
|
|
|
'tag_ids': False, |
|
|
|
'currency_id': False, |
|
|
|
}) |
|
|
|
centralized_ml[jnl_id][month]['debit'] += move_line['debit'] |
|
|
|
centralized_ml[jnl_id][month]['credit'] += move_line['credit'] |
|
|
|
centralized_ml[jnl_id][month]["balance"] += move_line["debit"] - \ |
|
|
|
move_line["credit"] |
|
|
|
centralized_ml[jnl_id][month]['bal_curr'] += move_line['bal_curr'] |
|
|
|
return centralized_ml |
|
|
|
|
|
|
|
@api.model |
|
|
|
def _get_centralized_ml(self, account, date_to): |
|
|
|
centralized_ml = {} |
|
|
|
if isinstance(date_to, str): |
|
|
|
date_to = datetime.datetime.strptime(date_to, '%Y-%m-%d').date() |
|
|
|
for partner in partners: |
|
|
|
for move_line in partner['move_lines']: |
|
|
|
jnl_id = move_line['journal_id'] |
|
|
|
month = move_line['date'].month |
|
|
|
if jnl_id not in centralized_ml.keys(): |
|
|
|
centralized_ml[jnl_id] = {} |
|
|
|
if month not in centralized_ml[jnl_id].keys(): |
|
|
|
centralized_ml[jnl_id][month] = {} |
|
|
|
last_day_month = \ |
|
|
|
calendar.monthrange(move_line['date'].year, month) |
|
|
|
date = datetime.date( |
|
|
|
move_line['date'].year, |
|
|
|
month, |
|
|
|
last_day_month[1]) |
|
|
|
if date > date_to: |
|
|
|
date = date_to |
|
|
|
centralized_ml[jnl_id][month].update({ |
|
|
|
'journal_id': jnl_id, |
|
|
|
'ref': 'Centralized entries', |
|
|
|
'date': date, |
|
|
|
'debit': 0.0, |
|
|
|
'credit': 0.0, |
|
|
|
'balance': 0.0, |
|
|
|
'bal_curr': 0.0, |
|
|
|
'partner_id': False, |
|
|
|
'rec_id': 0, |
|
|
|
'entry_id': False, |
|
|
|
'tax_ids': [], |
|
|
|
'full_reconcile_id': False, |
|
|
|
'id': False, |
|
|
|
'tag_ids': False, |
|
|
|
'currency_id': False, |
|
|
|
}) |
|
|
|
centralized_ml[jnl_id][month]['debit'] += move_line['debit'] |
|
|
|
centralized_ml[jnl_id][month]['credit'] += move_line['credit'] |
|
|
|
centralized_ml[jnl_id][month]['balance'] += move_line['balance'] |
|
|
|
centralized_ml[jnl_id][month]['bal_curr'] += move_line['bal_curr'] |
|
|
|
if account['partners']: |
|
|
|
for partner in account['list_partner']: |
|
|
|
for move_line in partner['move_lines']: |
|
|
|
centralized_ml = self._calculate_centralization( |
|
|
|
centralized_ml, |
|
|
|
move_line, |
|
|
|
date_to, |
|
|
|
) |
|
|
|
else: |
|
|
|
for move_line in account['move_lines']: |
|
|
|
centralized_ml = self._calculate_centralization( |
|
|
|
centralized_ml, |
|
|
|
move_line, |
|
|
|
date_to, |
|
|
|
) |
|
|
|
list_centralized_ml = [] |
|
|
|
for jnl_id in centralized_ml.keys(): |
|
|
|
list_centralized_ml += list(centralized_ml[jnl_id].values()) |
|
|
@ -579,12 +604,17 @@ class GeneralLedgerReport(models.AbstractModel): |
|
|
|
general_ledger = self._create_general_ledger(gen_ld_data, accounts_data) |
|
|
|
if centralize: |
|
|
|
for account in general_ledger: |
|
|
|
if account['partners']: |
|
|
|
if account['centralized']: |
|
|
|
centralized_ml = self._get_centralized_ml( |
|
|
|
account['list_partner'], date_to) |
|
|
|
account, date_to) |
|
|
|
account['move_lines'] = centralized_ml |
|
|
|
account['partners'] = False |
|
|
|
del account['list_partner'] |
|
|
|
account["move_lines"] = self._recalculate_cumul_balance( |
|
|
|
account["move_lines"], |
|
|
|
gen_ld_data[account["id"]]["init_bal"]["balance"], |
|
|
|
) |
|
|
|
if account['partners']: |
|
|
|
account['partners'] = False |
|
|
|
del account['list_partner'] |
|
|
|
general_ledger = sorted(general_ledger, key=lambda k: k['code']) |
|
|
|
return { |
|
|
|
'doc_ids': [wizard_id], |
|
|
|