[IMP] account_financial_report: extensibility: ml fields

pull/990/head
AaronHForgeFlow 2022-11-22 12:55:01 +01:00 committed by Miquel Raïch
parent 9acc89c7d1
commit e69b6ae74c
5 changed files with 68 additions and 76 deletions

View File

@ -7,6 +7,16 @@ from odoo import api, models
class AgedPartnerBalanceReport(models.AbstractModel): class AgedPartnerBalanceReport(models.AbstractModel):
_name = "report.account_financial_report.abstract_report" _name = "report.account_financial_report.abstract_report"
_description = "Abstract Report" _description = "Abstract Report"
COMMON_ML_FIELDS = [
"account_id",
"partner_id",
"journal_id",
"date",
"ref",
"id",
"move_id",
"name",
]
@api.model @api.model
def _get_move_lines_domain_not_reconciled( def _get_move_lines_domain_not_reconciled(
@ -68,24 +78,7 @@ class AgedPartnerBalanceReport(models.AbstractModel):
new_domain = self._get_new_move_lines_domain( new_domain = self._get_new_move_lines_domain(
new_ml_ids, account_ids, company_id, partner_ids, only_posted_moves new_ml_ids, account_ids, company_id, partner_ids, only_posted_moves
) )
ml_fields = [ ml_fields = self._get_ml_fields()
"id",
"name",
"date",
"move_id",
"journal_id",
"account_id",
"partner_id",
"amount_residual",
"date_maturity",
"ref",
"debit",
"credit",
"reconciled",
"currency_id",
"amount_currency",
"amount_residual_currency",
]
new_move_lines = self.env["account.move.line"].search_read( new_move_lines = self.env["account.move.line"].search_read(
domain=new_domain, fields=ml_fields domain=new_domain, fields=ml_fields
) )
@ -124,3 +117,15 @@ class AgedPartnerBalanceReport(models.AbstractModel):
for journal in journals: for journal in journals:
journals_data.update({journal.id: {"id": journal.id, "code": journal.code}}) journals_data.update({journal.id: {"id": journal.id, "code": journal.code}})
return journals_data return journals_data
def _get_ml_fields(self):
return self.COMMON_ML_FIELDS + [
"amount_residual",
"reconciled",
"currency_id",
"credit",
"date_maturity",
"amount_residual_currency",
"debit",
"amount_currency",
]

View File

@ -103,19 +103,7 @@ class AgedPartnerBalanceReport(models.AbstractModel):
domain = self._get_move_lines_domain_not_reconciled( domain = self._get_move_lines_domain_not_reconciled(
company_id, account_ids, partner_ids, only_posted_moves, date_from company_id, account_ids, partner_ids, only_posted_moves, date_from
) )
ml_fields = [ ml_fields = self._get_ml_fields()
"id",
"name",
"date",
"move_id",
"journal_id",
"account_id",
"partner_id",
"amount_residual",
"date_maturity",
"ref",
"reconciled",
]
line_model = self.env["account.move.line"] line_model = self.env["account.move.line"]
move_lines = line_model.search_read(domain=domain, fields=ml_fields) move_lines = line_model.search_read(domain=domain, fields=ml_fields)
journals_ids = set() journals_ids = set()
@ -375,3 +363,10 @@ class AgedPartnerBalanceReport(models.AbstractModel):
"aged_partner_balance": aged_partner_data, "aged_partner_balance": aged_partner_data,
"show_move_lines_details": show_move_line_details, "show_move_lines_details": show_move_line_details,
} }
def _get_ml_fields(self):
return self.COMMON_ML_FIELDS + [
"amount_residual",
"reconciled",
"date_maturity",
]

View File

@ -458,26 +458,7 @@ class GeneralLedgerReport(models.AbstractModel):
) )
if extra_domain: if extra_domain:
domain += extra_domain domain += extra_domain
ml_fields = [ ml_fields = self._get_ml_fields()
"id",
"name",
"date",
"move_id",
"journal_id",
"account_id",
"partner_id",
"debit",
"credit",
"balance",
"currency_id",
"full_reconcile_id",
"tax_ids",
"tax_line_id",
"amount_currency",
"ref",
"name",
"analytic_distribution",
]
move_lines = self.env["account.move.line"].search_read( move_lines = self.env["account.move.line"].search_read(
domain=domain, fields=ml_fields domain=domain, fields=ml_fields
) )
@ -880,3 +861,16 @@ class GeneralLedgerReport(models.AbstractModel):
"filter_partner_ids": True if partner_ids else False, "filter_partner_ids": True if partner_ids else False,
"currency_model": self.env["res.currency"], "currency_model": self.env["res.currency"],
} }
def _get_ml_fields(self):
return self.COMMON_ML_FIELDS + [
"analytic_distribution",
"full_reconcile_id",
"tax_line_id",
"currency_id",
"credit",
"debit",
"amount_currency",
"balance",
"tax_ids",
]

View File

@ -48,24 +48,7 @@ class OpenItemsReport(models.AbstractModel):
domain = self._get_move_lines_domain_not_reconciled( domain = self._get_move_lines_domain_not_reconciled(
company_id, account_ids, partner_ids, only_posted_moves, date_from company_id, account_ids, partner_ids, only_posted_moves, date_from
) )
ml_fields = [ ml_fields = self._get_ml_fields()
"id",
"name",
"date",
"move_id",
"journal_id",
"account_id",
"partner_id",
"amount_residual",
"date_maturity",
"ref",
"debit",
"credit",
"reconciled",
"currency_id",
"amount_currency",
"amount_residual_currency",
]
move_lines = self.env["account.move.line"].search_read( move_lines = self.env["account.move.line"].search_read(
domain=domain, fields=ml_fields domain=domain, fields=ml_fields
) )
@ -272,3 +255,15 @@ class OpenItemsReport(models.AbstractModel):
"total_amount": total_amount, "total_amount": total_amount,
"Open_Items": open_items_move_lines_data, "Open_Items": open_items_move_lines_data,
} }
def _get_ml_fields(self):
return self.COMMON_ML_FIELDS + [
"amount_residual",
"reconciled",
"currency_id",
"credit",
"date_maturity",
"amount_residual_currency",
"debit",
"amount_currency",
]

View File

@ -60,13 +60,7 @@ class VATReport(models.AbstractModel):
tax_domain = self._get_tax_report_domain( tax_domain = self._get_tax_report_domain(
company_id, date_from, date_to, only_posted_moves company_id, date_from, date_to, only_posted_moves
) )
ml_fields = [ ml_fields = self._get_ml_fields_vat_report()
"id",
"tax_base_amount",
"balance",
"tax_line_id",
"tax_ids",
]
tax_move_lines = self.env["account.move.line"].search_read( tax_move_lines = self.env["account.move.line"].search_read(
domain=tax_domain, domain=tax_domain,
fields=ml_fields, fields=ml_fields,
@ -234,3 +228,12 @@ class VATReport(models.AbstractModel):
"tax_detail": data["tax_detail"], "tax_detail": data["tax_detail"],
"vat_report": vat_report, "vat_report": vat_report,
} }
def _get_ml_fields_vat_report(self):
return [
"id",
"tax_base_amount",
"balance",
"tax_line_id",
"tax_ids",
]