|
| 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 |
0 commit comments