[IMP] account_fiscal_month: black, isort, prettier
This commit is contained in:
parent
f639f10508
commit
f3e658fefb
@ -2,18 +2,12 @@
|
|||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
{
|
{
|
||||||
'name': 'Account Fiscal Month',
|
"name": "Account Fiscal Month",
|
||||||
'summary': """Provide a fiscal month date range type""",
|
"summary": """Provide a fiscal month date range type""",
|
||||||
'version': '12.0.1.0.0',
|
"version": "12.0.1.0.0",
|
||||||
'license': 'AGPL-3',
|
"license": "AGPL-3",
|
||||||
'author': 'ACSONE SA/NV, Odoo Community Association (OCA)',
|
"author": "ACSONE SA/NV, Odoo Community Association (OCA)",
|
||||||
'website': 'https://github.com/OCA/account-financial-tools',
|
"website": "https://github.com/OCA/account-financial-tools",
|
||||||
'depends': [
|
"depends": ["account", "date_range",],
|
||||||
'account',
|
"data": ["data/date_range_type.xml", "views/date_range_type.xml",],
|
||||||
'date_range',
|
|
||||||
],
|
|
||||||
'data': [
|
|
||||||
'data/date_range_type.xml',
|
|
||||||
'views/date_range_type.xml',
|
|
||||||
],
|
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,10 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
<!-- Copyright 2017 ACSONE SA/NV
|
<!-- Copyright 2017 ACSONE SA/NV
|
||||||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
|
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
|
||||||
|
|
||||||
<odoo noupdate="1">
|
<odoo noupdate="1">
|
||||||
|
|
||||||
<record model="date.range.type" id="date_range_fiscal_month">
|
<record model="date.range.type" id="date_range_fiscal_month">
|
||||||
<field name="name">Fiscal month</field>
|
<field name="name">Fiscal month</field>
|
||||||
<field name="allow_overlap" eval="False"/>
|
<field name="allow_overlap" eval="False" />
|
||||||
<field name="fiscal_month" eval="True"/>
|
<field name="fiscal_month" eval="True" />
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
</odoo>
|
</odoo>
|
||||||
|
@ -1,20 +1,20 @@
|
|||||||
# Copyright 2017 ACSONE SA/NV
|
# Copyright 2017 ACSONE SA/NV
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
from odoo import api, fields, models, _
|
from odoo import _, api, fields, models
|
||||||
from odoo.exceptions import UserError
|
from odoo.exceptions import UserError
|
||||||
|
|
||||||
|
|
||||||
class DateRangeType(models.Model):
|
class DateRangeType(models.Model):
|
||||||
_inherit = 'date.range.type'
|
_inherit = "date.range.type"
|
||||||
|
|
||||||
fiscal_month = fields.Boolean(string="Is fiscal month?", readonly=True)
|
fiscal_month = fields.Boolean(string="Is fiscal month?", readonly=True)
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def unlink(self):
|
def unlink(self):
|
||||||
date_range_type_fm = self.env.ref(
|
date_range_type_fm = self.env.ref(
|
||||||
'account_fiscal_month.date_range_fiscal_month')
|
"account_fiscal_month.date_range_fiscal_month"
|
||||||
|
)
|
||||||
if date_range_type_fm.id in self.ids:
|
if date_range_type_fm.id in self.ids:
|
||||||
raise UserError(_("You can't delete date range type: "
|
raise UserError(_("You can't delete date range type: " "Fiscal month"))
|
||||||
"Fiscal month"))
|
|
||||||
return super(DateRangeType, self).unlink()
|
return super(DateRangeType, self).unlink()
|
||||||
|
@ -6,17 +6,21 @@ from odoo import api, models
|
|||||||
|
|
||||||
class ResCompany(models.Model):
|
class ResCompany(models.Model):
|
||||||
|
|
||||||
_inherit = 'res.company'
|
_inherit = "res.company"
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def find_daterange_fm(self, date_str):
|
def find_daterange_fm(self, date_str):
|
||||||
self.ensure_one()
|
self.ensure_one()
|
||||||
fm_id = self.env.ref('account_fiscal_month.date_range_fiscal_month')
|
fm_id = self.env.ref("account_fiscal_month.date_range_fiscal_month")
|
||||||
return self.env['date.range'].search([
|
return self.env["date.range"].search(
|
||||||
('type_id', '=', fm_id.id),
|
[
|
||||||
('date_start', '<=', date_str),
|
("type_id", "=", fm_id.id),
|
||||||
('date_end', '>=', date_str),
|
("date_start", "<=", date_str),
|
||||||
'|',
|
("date_end", ">=", date_str),
|
||||||
('company_id', '=', self.id),
|
"|",
|
||||||
('company_id', '=', False),
|
("company_id", "=", self.id),
|
||||||
], limit=1, order='company_id asc')
|
("company_id", "=", False),
|
||||||
|
],
|
||||||
|
limit=1,
|
||||||
|
order="company_id asc",
|
||||||
|
)
|
||||||
|
@ -1,53 +1,60 @@
|
|||||||
# Copyright 2017 ACSONE SA/NV
|
# Copyright 2017 ACSONE SA/NV
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
|
from psycopg2 import IntegrityError
|
||||||
|
|
||||||
from odoo.exceptions import UserError
|
from odoo.exceptions import UserError
|
||||||
from odoo.fields import Date
|
from odoo.fields import Date
|
||||||
from odoo.tests.common import TransactionCase
|
from odoo.tests.common import TransactionCase
|
||||||
from odoo.tools import mute_logger
|
from odoo.tools import mute_logger
|
||||||
from psycopg2 import IntegrityError
|
|
||||||
|
|
||||||
|
|
||||||
class TestAccountFiscalMonth(TransactionCase):
|
class TestAccountFiscalMonth(TransactionCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestAccountFiscalMonth, self).setUp()
|
super(TestAccountFiscalMonth, self).setUp()
|
||||||
self.DateRangeObj = self.env['date.range']
|
self.DateRangeObj = self.env["date.range"]
|
||||||
self.DateRangeType = self.env['date.range.type']
|
self.DateRangeType = self.env["date.range.type"]
|
||||||
|
|
||||||
self.company = self.env.ref('base.main_company')
|
self.company = self.env.ref("base.main_company")
|
||||||
|
|
||||||
self.date_range_type = self.DateRangeType.create(
|
self.date_range_type = self.DateRangeType.create(
|
||||||
{'name': 'Other Type',
|
{"name": "Other Type", "allow_overlap": False}
|
||||||
'allow_overlap': False})
|
)
|
||||||
self.date_range_type_month = self.env.ref(
|
self.date_range_type_month = self.env.ref(
|
||||||
'account_fiscal_month.date_range_fiscal_month')
|
"account_fiscal_month.date_range_fiscal_month"
|
||||||
|
)
|
||||||
|
|
||||||
self.date_range_1 = self.DateRangeObj.create({
|
self.date_range_1 = self.DateRangeObj.create(
|
||||||
'name': "Other",
|
{
|
||||||
'date_start': '2017-01-01',
|
"name": "Other",
|
||||||
'date_end': '2017-01-31',
|
"date_start": "2017-01-01",
|
||||||
'type_id': self.date_range_type.id,
|
"date_end": "2017-01-31",
|
||||||
'company_id': self.company.id,
|
"type_id": self.date_range_type.id,
|
||||||
})
|
"company_id": self.company.id,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
self.date_range_january_2017 = self.DateRangeObj.create({
|
self.date_range_january_2017 = self.DateRangeObj.create(
|
||||||
'name': "January 2017",
|
{
|
||||||
'date_start': '2017-01-01',
|
"name": "January 2017",
|
||||||
'date_end': '2017-01-31',
|
"date_start": "2017-01-01",
|
||||||
'type_id': self.date_range_type_month.id,
|
"date_end": "2017-01-31",
|
||||||
'company_id': self.company.id,
|
"type_id": self.date_range_type_month.id,
|
||||||
})
|
"company_id": self.company.id,
|
||||||
self.date_range_january_no_comp_2017 = self.DateRangeObj.create({
|
}
|
||||||
'name': "January 2017",
|
)
|
||||||
'date_start': '2017-01-01',
|
self.date_range_january_no_comp_2017 = self.DateRangeObj.create(
|
||||||
'date_end': '2017-01-31',
|
{
|
||||||
'type_id': self.date_range_type_month.id,
|
"name": "January 2017",
|
||||||
'company_id': False,
|
"date_start": "2017-01-01",
|
||||||
})
|
"date_end": "2017-01-31",
|
||||||
|
"type_id": self.date_range_type_month.id,
|
||||||
|
"company_id": False,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
def test_00_delete_type(self):
|
def test_00_delete_type(self):
|
||||||
with self.assertRaises(IntegrityError), mute_logger('odoo.sql_db'):
|
with self.assertRaises(IntegrityError), mute_logger("odoo.sql_db"):
|
||||||
self.date_range_type.unlink()
|
self.date_range_type.unlink()
|
||||||
|
|
||||||
def test_01_delete_type_fiscal_month(self):
|
def test_01_delete_type_fiscal_month(self):
|
||||||
@ -55,7 +62,7 @@ class TestAccountFiscalMonth(TransactionCase):
|
|||||||
self.date_range_type_month.unlink()
|
self.date_range_type_month.unlink()
|
||||||
|
|
||||||
def test_02_search_date_range(self):
|
def test_02_search_date_range(self):
|
||||||
january_2017_1st = Date.from_string('2017-01-01')
|
january_2017_1st = Date.from_string("2017-01-01")
|
||||||
date_ranges = self.company.find_daterange_fm(january_2017_1st)
|
date_ranges = self.company.find_daterange_fm(january_2017_1st)
|
||||||
|
|
||||||
self.assertEquals(len(date_ranges), 1)
|
self.assertEquals(len(date_ranges), 1)
|
||||||
|
@ -1,33 +1,25 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
<!-- Copyright 2017 ACSONE SA/NV
|
<!-- Copyright 2017 ACSONE SA/NV
|
||||||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
|
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
|
||||||
|
|
||||||
<odoo>
|
<odoo>
|
||||||
|
|
||||||
<record model="ir.ui.view" id="date_range_type_form_view">
|
<record model="ir.ui.view" id="date_range_type_form_view">
|
||||||
<field name="name">date.range.type.form (in account_fiscal_month)</field>
|
<field name="name">date.range.type.form (in account_fiscal_month)</field>
|
||||||
<field name="model">date.range.type</field>
|
<field name="model">date.range.type</field>
|
||||||
<field name="inherit_id" ref="date_range.view_date_range_type_form_view"/>
|
<field name="inherit_id" ref="date_range.view_date_range_type_form_view" />
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
|
|
||||||
<field name="allow_overlap" position="after">
|
<field name="allow_overlap" position="after">
|
||||||
<field name="fiscal_month"/>
|
<field name="fiscal_month" />
|
||||||
</field>
|
</field>
|
||||||
|
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
<record model="ir.ui.view" id="date_range_type_tree_view">
|
<record model="ir.ui.view" id="date_range_type_tree_view">
|
||||||
<field name="name">date.range.type.tree (in account_fiscal_month)</field>
|
<field name="name">date.range.type.tree (in account_fiscal_month)</field>
|
||||||
<field name="model">date.range.type</field>
|
<field name="model">date.range.type</field>
|
||||||
<field name="inherit_id" ref="date_range.view_date_range_type_tree"/>
|
<field name="inherit_id" ref="date_range.view_date_range_type_tree" />
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
|
|
||||||
<field name="allow_overlap" position="after">
|
<field name="allow_overlap" position="after">
|
||||||
<field name="fiscal_month"/>
|
<field name="fiscal_month" />
|
||||||
</field>
|
</field>
|
||||||
|
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
</odoo>
|
</odoo>
|
||||||
|
Loading…
Reference in New Issue
Block a user