Skip to content

Commit 0d5075d

Browse files
sebastienbeauPierrick Brun
authored and
Pierrick Brun
committed
[IMP] start module for maintenance and migration pricing
1 parent 6d5e29b commit 0d5075d

8 files changed

+216
-0
lines changed

module_analysis_price/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import models

module_analysis_price/__manifest__.py

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Copyright 2021 Akretion (https://www.akretion.com).
2+
# @author Sébastien BEAU <sebastien.beau@akretion.com>
3+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
4+
5+
{
6+
"name": "Module Analysis Price",
7+
"summary": "Module Analysis Price",
8+
"version": "14.0.1.0.0",
9+
"website": "https://github.com/akretion/ak-odoo-incubator",
10+
"author": " Akretion",
11+
"license": "AGPL-3",
12+
"application": False,
13+
"installable": True,
14+
"external_dependencies": {
15+
"python": [],
16+
"bin": [],
17+
},
18+
"depends": [
19+
"module_analysis",
20+
],
21+
"data": [
22+
"views/ir_module_type_view.xml",
23+
"views/ir_module_author_view.xml",
24+
],
25+
"demo": [],
26+
}
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from . import ir_module_type
2+
from . import ir_module_author
3+
from . import ir_module_module
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Copyright 2021 Akretion (https://www.akretion.com).
2+
# @author Sébastien BEAU <sebastien.beau@akretion.com>
3+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
4+
5+
from odoo import api, fields, models
6+
7+
8+
class IrModuleAuthor(models.Model):
9+
_inherit = "ir.module.author"
10+
11+
community_installed_module_qty = fields.Integer(
12+
compute="_compute_community_rate", store=True
13+
)
14+
community_installed_module_rate = fields.Float(
15+
compute="_compute_community_rate", store=True
16+
)
17+
community_installed_code_qty = fields.Integer(
18+
compute="_compute_community_rate", store=True
19+
)
20+
community_installed_code_rate = fields.Float(
21+
compute="_compute_community_rate", store=True
22+
)
23+
24+
@api.depends(
25+
"installed_module_ids.code_qty",
26+
"installed_module_ids.module_type_id.community",
27+
)
28+
def _compute_community_rate(self):
29+
type_community = self.env["ir.module.type"].search([("community", "=", True)])
30+
if type_community:
31+
total_code_qty = sum(type_community.mapped("code_qty"))
32+
total_module_qty = len(type_community.installed_module_ids)
33+
for record in self:
34+
modules = record.installed_module_ids.filtered(
35+
"module_type_id.community"
36+
)
37+
record.community_installed_code_qty = sum(modules.mapped("code_qty"))
38+
record.community_installed_code_rate = (
39+
100 * sum(modules.mapped("code_qty")) / total_code_qty
40+
)
41+
record.community_installed_module_qty = len(modules)
42+
record.community_installed_module_rate = (
43+
100 * len(modules) / total_module_qty
44+
)
45+
else:
46+
for record in self:
47+
record.community_rate = 0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Copyright 2021 Akretion (https://www.akretion.com).
2+
# @author Sébastien BEAU <sebastien.beau@akretion.com>
3+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
4+
5+
6+
from odoo import fields, models
7+
8+
9+
class IrModuleModule(models.Model):
10+
_inherit = "ir.module.module"
11+
12+
code_qty = fields.Integer(
13+
string="Total Code Quantity (Python, xml, JS)",
14+
compute="_compute_code_qty",
15+
store=True,
16+
)
17+
18+
def _compute_code_qty(self):
19+
for record in self:
20+
record.code_qty = (
21+
record.python_code_qty + record.xml_code_qty + record.js_code_qty
22+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Copyright 2021 Akretion (https://www.akretion.com).
2+
# @author Sébastien BEAU <sebastien.beau@akretion.com>
3+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
4+
5+
6+
from odoo import api, fields, models
7+
8+
# number of line per a page of a book
9+
QTY_PER_PAGE = 35
10+
11+
12+
class IrModuleType(models.Model):
13+
_inherit = "ir.module.type"
14+
15+
sequence = fields.Integer()
16+
code_qty = fields.Integer(
17+
string="Code Quantity", compute="_compute_code_qty", store=True
18+
)
19+
page_qty = fields.Integer(
20+
string="Page Qty", compute="_compute_code_qty", store=True
21+
)
22+
community = fields.Boolean()
23+
migration_price_unit = fields.Float()
24+
maintenance_price_unit = fields.Float()
25+
migration_monthly_price = fields.Float(compute="_compute_migration_price")
26+
migration_year_price = fields.Float(compute="_compute_migration_price")
27+
maintenance_monthly_price = fields.Float(compute="_compute_maintenance_price")
28+
maintenance_year_price = fields.Float(compute="_compute_maintenance_price")
29+
30+
@api.depends("migration_price_unit")
31+
def _compute_migration_price(self):
32+
return self._compute_total_price("migration")
33+
34+
@api.depends("maintenance_price_unit")
35+
def _compute_maintenance_price(self):
36+
return self._compute_total_price("maintenance")
37+
38+
def _compute_total_price(self, case):
39+
for record in self:
40+
record[f"{case}_monthly_price"] = record[f"{case}_price_unit"] * round(
41+
record.code_qty / 100
42+
)
43+
record[f"{case}_year_price"] = record[f"{case}_monthly_price"] * 12
44+
45+
@api.depends("installed_module_ids.code_qty")
46+
def _compute_code_qty(self):
47+
for record in self:
48+
record.code_qty = sum(record.installed_module_ids.mapped("code_qty"))
49+
record.page_qty = record.code_qty / QTY_PER_PAGE
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<odoo>
3+
4+
<record id="view_ir_module_author_tree" model="ir.ui.view">
5+
<field name="model">ir.module.author</field>
6+
<field name="inherit_id" ref="module_analysis.view_ir_module_author_tree" />
7+
<field name="arch" type="xml">
8+
<field name="installed_module_qty" position="after">
9+
<field name="community_installed_module_qty" />
10+
<field name="community_installed_module_rate" widget="progressbar" />
11+
<field name="community_installed_code_qty" />
12+
<field name="community_installed_code_rate" widget="progressbar" />
13+
</field>
14+
</field>
15+
</record>
16+
17+
</odoo>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<odoo>
3+
4+
<record id="view_ir_module_type_form" model="ir.ui.view">
5+
<field name="model">ir.module.type</field>
6+
<field name="inherit_id" ref="module_analysis.view_ir_module_type_form" />
7+
<field name="arch" type="xml">
8+
<group position="inside">
9+
<field name="code_qty" />
10+
<field name="community" />
11+
<field name="migration_price_unit" />
12+
<field name="maintenance_price_unit" />
13+
<field name="migration_monthly_price" />
14+
<field name="migration_year_price" />
15+
<field name="maintenance_monthly_price" />
16+
<field name="maintenance_year_price" />
17+
</group>
18+
</field>
19+
</record>
20+
21+
<record id="view_ir_module_type_tree" model="ir.ui.view">
22+
<field name="model">ir.module.type</field>
23+
<field name="inherit_id" ref="module_analysis.view_ir_module_type_tree" />
24+
<field name="arch" type="xml">
25+
<field name="installed_module_qty" position="after">
26+
<field name="code_qty" sum="Total Code Qty" />
27+
<field name="page_qty" sum="Total Page Qty" />
28+
<field name="maintenance_price_unit" />
29+
<field
30+
name="maintenance_monthly_price"
31+
sum="Total Maintenance Monthly Price"
32+
/>
33+
<field name="maintenance_year_price" sum="Total Maintenance Year Price" />
34+
<field name="migration_price_unit" />
35+
<field name="migration_monthly_price" sum="Total Migration Monthly Price" />
36+
<field name="migration_year_price" sum="Total Migration Year Price" />
37+
<field name="community" />
38+
</field>
39+
<field name="installed_module_qty" position="attributes">
40+
<attribute name="sum">Total Module Qty</attribute>
41+
</field>
42+
<tree position="attributes">
43+
<attribute name="editable">bottom</attribute>
44+
</tree>
45+
<field name="name" position="before">
46+
<field name="sequence" widget="handle" />
47+
</field>
48+
</field>
49+
</record>
50+
51+
</odoo>

0 commit comments

Comments
 (0)