add earnings in general ledger
This commit is contained in:
parent
8f7c5b7ac1
commit
1306043f22
@ -18,5 +18,5 @@ It is based on modules:
|
||||
### Trial Balance
|
||||
- Displays unaffected earnings and year's earnings
|
||||
|
||||
## Whats Needs to Be Done:
|
||||
- create résultat and report à nouveau lines in journal ledger export
|
||||
### General Ledger
|
||||
- Displays unaffected and year's earnings
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
'name': "Gn Financial Report",
|
||||
'version': '16.0.0.0.3',
|
||||
'version': '16.0.0.0.4',
|
||||
'author': 'Garage Numérique',
|
||||
'category': 'Accounting',
|
||||
'description': """
|
||||
|
||||
@ -1,3 +1,3 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from . import trial_balance
|
||||
from . import trial_balance, general_ledger
|
||||
249
gn_financial_report/report/general_ledger.py
Normal file
249
gn_financial_report/report/general_ledger.py
Normal file
@ -0,0 +1,249 @@
|
||||
import calendar
|
||||
import datetime
|
||||
import operator
|
||||
|
||||
from odoo import _, api, models
|
||||
from odoo.tools import float_is_zero
|
||||
|
||||
class GnGeneralLedgerReport(models.AbstractModel):
|
||||
_inherit = "report.account_financial_report.general_ledger"
|
||||
|
||||
def _get_year_balance_fy_pl_ml_domain(
|
||||
self, account_ids, company_id, date_from, date_to, base_domain
|
||||
):
|
||||
accounts_domain = [
|
||||
("company_id", "=", company_id),
|
||||
("include_initial_balance", "=", False),
|
||||
]
|
||||
if account_ids:
|
||||
accounts_domain += [("id", "in", account_ids)]
|
||||
domain = []
|
||||
domain += base_domain
|
||||
domain += [("date", ">=", date_from), ("date", "<=", date_to)]
|
||||
accounts = self.env["account.account"].search(accounts_domain)
|
||||
domain += [("account_id", "in", accounts.ids)]
|
||||
return domain
|
||||
|
||||
def _get_pl_year_balance(
|
||||
self, account_ids, company_id, date_from, date_to, foreign_currency, base_domain
|
||||
):
|
||||
domain = self._get_year_balance_fy_pl_ml_domain(
|
||||
account_ids, company_id, date_from, date_to, base_domain
|
||||
)
|
||||
year_balances = self.env["account.move.line"].read_group(
|
||||
domain=domain,
|
||||
fields=["account_id", "debit", "credit", "balance", "amount_currency:sum"],
|
||||
groupby=["account_id"],
|
||||
)
|
||||
pl_year_balance = {
|
||||
"debit": 0.0,
|
||||
"credit": 0.0,
|
||||
"balance": 0.0,
|
||||
"bal_curr": 0.0,
|
||||
}
|
||||
for year_balance in year_balances:
|
||||
pl_year_balance["debit"] += year_balance["debit"]
|
||||
pl_year_balance["credit"] += year_balance["credit"]
|
||||
pl_year_balance["balance"] += year_balance["balance"]
|
||||
pl_year_balance["bal_curr"] += year_balance["amount_currency"]
|
||||
return pl_year_balance
|
||||
|
||||
def _get_initial_balance_data(
|
||||
self,
|
||||
account_ids,
|
||||
partner_ids,
|
||||
company_id,
|
||||
date_from,
|
||||
date_to,
|
||||
foreign_currency,
|
||||
only_posted_moves,
|
||||
unaffected_earnings_account,
|
||||
fy_start_date,
|
||||
cost_center_ids,
|
||||
extra_domain,
|
||||
grouped_by,
|
||||
):
|
||||
# If explicit list of accounts is provided,
|
||||
# don't include unaffected earnings account
|
||||
if account_ids:
|
||||
unaffected_earnings_account = False
|
||||
base_domain = []
|
||||
if company_id:
|
||||
base_domain += [("company_id", "=", company_id)]
|
||||
if partner_ids:
|
||||
base_domain += [("partner_id", "in", partner_ids)]
|
||||
if only_posted_moves:
|
||||
base_domain += [("move_id.state", "=", "posted")]
|
||||
else:
|
||||
base_domain += [("move_id.state", "in", ["posted", "draft"])]
|
||||
if cost_center_ids:
|
||||
base_domain += [("analytic_account_ids", "in", cost_center_ids)]
|
||||
if extra_domain:
|
||||
base_domain += extra_domain
|
||||
gl_initial_acc = self._get_gl_initial_acc(
|
||||
account_ids, company_id, date_from, fy_start_date, base_domain, grouped_by
|
||||
)
|
||||
domain = self._get_initial_balances_bs_ml_domain(
|
||||
account_ids, company_id, date_from, base_domain, grouped_by, acc_prt=True
|
||||
)
|
||||
data = self._prepare_gen_ld_data(gl_initial_acc, domain, grouped_by)
|
||||
accounts_ids = list(data.keys())
|
||||
unaffected_id = unaffected_earnings_account
|
||||
if unaffected_id:
|
||||
result_profit_account = self.env['account.account'].search([('code', '=', '120000')])
|
||||
result_loss_account = self.env['account.account'].search([('code', '=', '129000')])
|
||||
unaffected_profit_account = self.env['account.account'].search([('code', '=', '110000')])
|
||||
unaffected_loss_account = self.env['account.account'].search([('code', '=', '119000')])
|
||||
|
||||
if result_profit_account and \
|
||||
result_loss_account and \
|
||||
unaffected_profit_account and \
|
||||
unaffected_loss_account:
|
||||
|
||||
result_profit_id = result_profit_account[0]['id']
|
||||
result_loss_id = result_loss_account[0]['id']
|
||||
unaffected_profit_id = unaffected_profit_account[0]['id']
|
||||
unaffected_loss_id = unaffected_loss_account[0]['id']
|
||||
|
||||
if result_profit_id and result_loss_id and \
|
||||
unaffected_profit_id and unaffected_loss_id:
|
||||
|
||||
for account_id in [result_profit_id, result_loss_id, unaffected_profit_id, unaffected_loss_id]:
|
||||
if account_id not in accounts_ids:
|
||||
accounts_ids.append(account_id)
|
||||
data[account_id] = self._initialize_data(foreign_currency)
|
||||
data[account_id]["id"] = unaffected_id
|
||||
data[account_id]["mame"] = ""
|
||||
data[account_id][grouped_by] = False
|
||||
|
||||
pl_initial_balance = self._get_pl_initial_balance(
|
||||
account_ids, company_id, fy_start_date, foreign_currency, base_domain
|
||||
)
|
||||
pl_year_balance = self._get_pl_year_balance(
|
||||
account_ids, company_id, date_from, date_to, foreign_currency, base_domain
|
||||
)
|
||||
for key_bal in ["init_bal", "fin_bal"]:
|
||||
fields_balance = ["credit", "debit", "balance"]
|
||||
if foreign_currency:
|
||||
fields_balance.append("bal_curr")
|
||||
for field_name in fields_balance:
|
||||
|
||||
if pl_initial_balance['balance'] > 0:
|
||||
data[unaffected_loss_id][key_bal][field_name] += pl_initial_balance[
|
||||
field_name
|
||||
]
|
||||
elif pl_initial_balance['balance'] < 0:
|
||||
data[unaffected_profit_id][key_bal][field_name] += pl_initial_balance[
|
||||
field_name
|
||||
]
|
||||
|
||||
if pl_year_balance['balance'] > 0:
|
||||
if key_bal == "fin_bal":
|
||||
data[result_loss_id][key_bal][field_name] += pl_year_balance[
|
||||
field_name
|
||||
]
|
||||
elif pl_year_balance['balance'] < 0:
|
||||
if key_bal == "fin_bal":
|
||||
data[result_profit_id][key_bal][field_name] += pl_year_balance[
|
||||
field_name
|
||||
]
|
||||
return data
|
||||
|
||||
def _get_report_values(self, docids, data):
|
||||
wizard_id = data["wizard_id"]
|
||||
company = self.env["res.company"].browse(data["company_id"])
|
||||
company_id = data["company_id"]
|
||||
date_to = data["date_to"]
|
||||
date_from = data["date_from"]
|
||||
partner_ids = data["partner_ids"]
|
||||
account_ids = data["account_ids"]
|
||||
cost_center_ids = data["cost_center_ids"]
|
||||
grouped_by = data["grouped_by"]
|
||||
hide_account_at_0 = data["hide_account_at_0"]
|
||||
foreign_currency = data["foreign_currency"]
|
||||
only_posted_moves = data["only_posted_moves"]
|
||||
unaffected_earnings_account = data["unaffected_earnings_account"]
|
||||
fy_start_date = data["fy_start_date"]
|
||||
extra_domain = data["domain"]
|
||||
gen_ld_data = self._get_initial_balance_data(
|
||||
account_ids,
|
||||
partner_ids,
|
||||
company_id,
|
||||
date_from,
|
||||
date_to,
|
||||
foreign_currency,
|
||||
only_posted_moves,
|
||||
unaffected_earnings_account,
|
||||
fy_start_date,
|
||||
cost_center_ids,
|
||||
extra_domain,
|
||||
grouped_by,
|
||||
)
|
||||
centralize = data["centralize"]
|
||||
(
|
||||
gen_ld_data,
|
||||
accounts_data,
|
||||
journals_data,
|
||||
full_reconcile_data,
|
||||
taxes_data,
|
||||
analytic_data,
|
||||
rec_after_date_to_ids,
|
||||
) = self._get_period_ml_data(
|
||||
account_ids,
|
||||
partner_ids,
|
||||
company_id,
|
||||
foreign_currency,
|
||||
only_posted_moves,
|
||||
date_from,
|
||||
date_to,
|
||||
gen_ld_data,
|
||||
cost_center_ids,
|
||||
extra_domain,
|
||||
grouped_by,
|
||||
)
|
||||
general_ledger = self._create_general_ledger(
|
||||
gen_ld_data,
|
||||
accounts_data,
|
||||
grouped_by,
|
||||
rec_after_date_to_ids,
|
||||
hide_account_at_0,
|
||||
)
|
||||
if centralize:
|
||||
for account in general_ledger:
|
||||
if account["centralized"]:
|
||||
centralized_ml = self._get_centralized_ml(
|
||||
account, date_to, grouped_by
|
||||
)
|
||||
account["move_lines"] = centralized_ml
|
||||
account["move_lines"] = self._recalculate_cumul_balance(
|
||||
account["move_lines"],
|
||||
gen_ld_data[account["id"]]["init_bal"]["balance"],
|
||||
rec_after_date_to_ids,
|
||||
)
|
||||
if grouped_by and account[grouped_by]:
|
||||
account[grouped_by] = False
|
||||
del account["list_grouped"]
|
||||
general_ledger = sorted(general_ledger, key=lambda k: k["code"])
|
||||
return {
|
||||
"doc_ids": [wizard_id],
|
||||
"doc_model": "general.ledger.report.wizard",
|
||||
"docs": self.env["general.ledger.report.wizard"].browse(wizard_id),
|
||||
"foreign_currency": data["foreign_currency"],
|
||||
"company_name": company.display_name,
|
||||
"company_currency": company.currency_id,
|
||||
"currency_name": company.currency_id.name,
|
||||
"date_from": data["date_from"],
|
||||
"date_to": data["date_to"],
|
||||
"only_posted_moves": data["only_posted_moves"],
|
||||
"hide_account_at_0": data["hide_account_at_0"],
|
||||
"show_cost_center": data["show_cost_center"],
|
||||
"general_ledger": general_ledger,
|
||||
"accounts_data": accounts_data,
|
||||
"journals_data": journals_data,
|
||||
"full_reconcile_data": full_reconcile_data,
|
||||
"taxes_data": taxes_data,
|
||||
"centralize": centralize,
|
||||
"analytic_data": analytic_data,
|
||||
"filter_partner_ids": True if partner_ids else False,
|
||||
"currency_model": self.env["res.currency"],
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user