Browse Source

[FIX] fix domain for fiscal year search

pull/134/head
houssine 4 years ago
parent
commit
dfe094f153
  1. 24
      easy_my_coop_loan_account/models/account_fiscal_year.py
  2. 1
      easy_my_coop_loan_account/wizard/__init__.py
  3. 44
      easy_my_coop_loan_account/wizard/end_of_year_operation.py
  4. 35
      easy_my_coop_loan_account/wizard/end_of_year_operation.xml

24
easy_my_coop_loan_account/models/account_fiscal_year.py

@ -16,30 +16,30 @@ class AccountFiscalYear(models.Model):
def get_ongoing_fiscal_year(self, company_id=None):
today = fields.Date.today()
fy = self.env["account.fiscal.year"].search([
('date_from', '>=', today),
('date_to', '<=', today),
('company_id', '=', company_id)
('date_from', '<=', today),
('date_to', '>=', today),
])
if not fy:
raise UserError("No fiscal year has been found for %d",
today)
raise UserError("No fiscal year has been found for %s" %
str(today))
if company_id:
return fy.filtered(lambda r: r.company_id == company_id)
return fy
@api.model
def get_next_fiscal_year(self, company_id=None):
nextyear = fields.Date.today() + relativedelta(years=+1)
def get_next_fiscal_year(self, date=None, company_id=None):
if not date:
date = fields.Date.today()
nextyear = date + relativedelta(years=+1)
fy = self.env["account.fiscal.year"].search([
('date_from', '>=', nextyear),
('date_to', '<=', nextyear),
('company_id', '=', company_id)
('date_from', '<=', nextyear),
('date_to', '>=', nextyear),
])
if not fy:
raise UserError("No next fiscal year has been found for %d",
nextyear)
raise UserError("No next fiscal year has been found for %s" %
str(nextyear))
if company_id:
return fy.filtered(lambda r: r.company_id == company_id)

1
easy_my_coop_loan_account/wizard/__init__.py

@ -0,0 +1 @@
from . import end_of_year_operation

44
easy_my_coop_loan_account/wizard/end_of_year_operation.py

@ -0,0 +1,44 @@
# Copyright 2020 Coop IT Easy SCRL fs
# Houssine BAKKALI <houssine@coopiteasy.be>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import api, fields, models
class LoanEndOfYearOperation(models.TransientModel):
_name = "loan.end.of.year.operation"
operation_type = fields.Selection(
[("eoy_debt", "End of year debt operation"),
("eoy_interest", "End of year interest operation")],
required=True,
string="Operation type"
)
ongoing_fy_id = fields.Many2one(
comodel_name="account.fiscal.year",
string="Ongoing fiscal year",
required=True
)
@api.multi
def run(self):
afy_obj = self.env["account.fiscal.year"]
loan_issues = self.env["loan.issue"].browse(
self._context.get("active_ids")
)
last_fy_day = self.ongoing_fy_id.date_to
next_fy = afy_obj.get_next_fiscal_year(last_fy_day)
if self.operation_type == "debt_eoy":
if next_fy:
interest_lines = self.search([
('due_date', '>=', next_fy.date_from),
('due_date', '<=', next_fy.date_to),
('due_loan_amount', '>', 0),
("loan_issue_id", "in", loan_issues.ids)
])
interest_lines.generate_loan_due_fy(last_fy_day)
elif self.operation_type == "eoy_interest":
print()

35
easy_my_coop_loan_account/wizard/end_of_year_operation.xml

@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="view_loan_end_of_year_operation" model="ir.ui.view">
<field name="name">End of year loan operation</field>
<field name="model">loan.end.of.year.operation</field>
<field name="arch" type="xml">
<form string="End of year loan operation">
<p class="oe_grey">
End of year loan operation.
</p>
<group>
<field name="operation_type"/>
<field name="ongoing_fy_id"/>
</group>
<footer>
<button name="run" string="Run" type="object"
class="btn-primary"/>
<button string="Cancel" class="btn-default"
special="cancel"/>
</footer>
</form>
</field>
</record>
<act_window id="action_view_loan_end_of_year_operation"
multi="True"
key2="client_action_multi"
name="End of year loan operation"
res_model="loan.end.of.year.operation"
src_model="loan.issue"
view_mode="form"
view_type="form"
target="new"
groups="easy_my_coop.group_easy_my_coop_manager"/>
</odoo>
Loading…
Cancel
Save