Initial commit: Odoo 18.0-20251222 extra-addons
This commit is contained in:
4
maintenance_product/models/__init__.py
Normal file
4
maintenance_product/models/__init__.py
Normal file
@@ -0,0 +1,4 @@
|
||||
from . import maintenance_equipment
|
||||
from . import product_category
|
||||
from . import product_product
|
||||
from . import product_template
|
||||
48
maintenance_product/models/maintenance_equipment.py
Normal file
48
maintenance_product/models/maintenance_equipment.py
Normal file
@@ -0,0 +1,48 @@
|
||||
# Copyright 2022 Tecnativa - Víctor Martínez
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class MaintenanceEquipment(models.Model):
|
||||
_inherit = "maintenance.equipment"
|
||||
|
||||
product_id = fields.Many2one(
|
||||
comodel_name="product.product",
|
||||
string="Product",
|
||||
tracking=True,
|
||||
domain="""
|
||||
[
|
||||
('categ_id', 'child_of', product_category_id),
|
||||
('maintenance_ok', '=', True),
|
||||
]
|
||||
""",
|
||||
)
|
||||
product_category_id = fields.Many2one(
|
||||
comodel_name="product.category", related="category_id.product_category_id"
|
||||
)
|
||||
|
||||
@api.onchange("product_id")
|
||||
def _onchange_product_id(self):
|
||||
"""If product is set, equipment name, seller, seller ref and cost defaults
|
||||
to product ones.
|
||||
"""
|
||||
if self.product_id:
|
||||
self.name = self.product_id.name
|
||||
self.cost = self.product_id.standard_price
|
||||
if self.product_id.seller_ids:
|
||||
first_seller = fields.first(self.product_id.seller_ids)
|
||||
self.partner_id = first_seller.partner_id
|
||||
self.partner_ref = first_seller.product_code
|
||||
|
||||
|
||||
class MaintenanceEquipmentCategory(models.Model):
|
||||
_inherit = "maintenance.equipment.category"
|
||||
|
||||
product_category_id = fields.Many2one(
|
||||
comodel_name="product.category", string="Product Category", tracking=True
|
||||
)
|
||||
|
||||
@api.onchange("product_category_id")
|
||||
def _onchange_product_category_id(self):
|
||||
if self.product_category_id:
|
||||
self.name = self.product_category_id.name
|
||||
13
maintenance_product/models/product_category.py
Normal file
13
maintenance_product/models/product_category.py
Normal file
@@ -0,0 +1,13 @@
|
||||
# Copyright 2022 Tecnativa - Víctor Martínez
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class ProductCategory(models.Model):
|
||||
_inherit = "product.category"
|
||||
|
||||
equipment_category_ids = fields.One2many(
|
||||
comodel_name="maintenance.equipment.category",
|
||||
inverse_name="product_category_id",
|
||||
string="Equipment Categories",
|
||||
)
|
||||
13
maintenance_product/models/product_product.py
Normal file
13
maintenance_product/models/product_product.py
Normal file
@@ -0,0 +1,13 @@
|
||||
# Copyright 2022 Tecnativa - Víctor Martínez
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class ProductProduct(models.Model):
|
||||
_inherit = "product.product"
|
||||
|
||||
equipment_ids = fields.One2many(
|
||||
comodel_name="maintenance.equipment",
|
||||
inverse_name="product_id",
|
||||
string="Equipments",
|
||||
)
|
||||
9
maintenance_product/models/product_template.py
Normal file
9
maintenance_product/models/product_template.py
Normal file
@@ -0,0 +1,9 @@
|
||||
# Copyright 2022 Tecnativa - Víctor Martínez
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class ProductTemplate(models.Model):
|
||||
_inherit = "product.template"
|
||||
|
||||
maintenance_ok = fields.Boolean(string="Can be Maintenance")
|
||||
Reference in New Issue
Block a user