-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
307 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Maintenance Equipment Stock | ||
=========================== | ||
|
||
Create Equipment from stock pickings in an easy way |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Copyright 2023 Dixmit | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
{ | ||
"name": "Maintenance Equipment Stock", | ||
"summary": """ | ||
Create equipments from stocks""", | ||
"version": "14.0.1.0.0", | ||
"license": "AGPL-3", | ||
"author": "Dixmit", | ||
"website": "https://github.com/oxigensalud/odoo-addons", | ||
"depends": [ | ||
"maintenance", | ||
"purchase_stock", | ||
], | ||
"data": [ | ||
"views/stock_picking.xml", | ||
"views/stock_production_lot.xml", | ||
"views/maintenance_equipment.xml", | ||
"views/product_template.xml", | ||
], | ||
"demo": [], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from . import product_template | ||
from . import maintenance_equipment | ||
from . import stock_production_lot | ||
from . import stock_move_line | ||
from . import stock_picking |
13 changes: 13 additions & 0 deletions
13
maintenance_equipment_stock/models/maintenance_equipment.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Copyright 2023 Dixmit | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import fields, models | ||
|
||
|
||
class MaintenanceEquipment(models.Model): | ||
_inherit = "maintenance.equipment" | ||
|
||
lot_id = fields.Many2one("stock.production.lot", readonly=True) | ||
picking_id = fields.Many2one("stock.picking", readonly=True) | ||
stock_move_line_id = fields.Many2one("stock.move.line", readonly=True) | ||
purchase_id = fields.Many2one("purchase.order", readonly=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Copyright 2023 Dixmit | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import fields, models | ||
|
||
|
||
class ProductTemplate(models.Model): | ||
_inherit = "product.template" | ||
|
||
maintenance_lot = fields.Boolean() | ||
maintenance_category_id = fields.Many2one("maintenance.equipment.category") | ||
maintenance_team_id = fields.Many2one("maintenance.team") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Copyright 2023 Dixmit | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import models | ||
|
||
|
||
class StockMoveLine(models.Model): | ||
|
||
_inherit = "stock.move.line" | ||
|
||
def _action_done(self): | ||
result = super()._action_done() | ||
for ml in self.filtered(lambda m: m.exists()): | ||
if ( | ||
ml.product_id.maintenance_lot | ||
and ml.product_id.type == "product" | ||
and ml.product_id.tracking == "serial" | ||
): | ||
ml._create_maintenance_equipment() | ||
return result | ||
|
||
def _create_maintenance_equipment(self): | ||
return self.env["maintenance.equipment"].create( | ||
self._create_maintenance_equipment_vals() | ||
) | ||
|
||
def _create_maintenance_equipment_vals(self): | ||
return { | ||
"lot_id": self.lot_id.id, | ||
"picking_id": self.move_id.picking_id.id, | ||
"stock_move_line_id": self.id, | ||
"name": self.product_id.display_name, | ||
"company_id": self.company_id.id, | ||
"partner_id": self.move_id.picking_id.partner_id.id, | ||
"category_id": self.product_id.maintenance_category_id.id, | ||
"maintenance_team_id": self.product_id.maintenance_team_id.id, | ||
"purchase_id": self.move_id.picking_id.purchase_id.id, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Copyright 2023 Dixmit | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import fields, models | ||
|
||
|
||
class StockPicking(models.Model): | ||
|
||
_inherit = "stock.picking" | ||
|
||
maintenance_equipment_ids = fields.One2many( | ||
"maintenance.equipment", inverse_name="picking_id" | ||
) | ||
maintenance_equipment_count = fields.Integer( | ||
compute="_compute_maintenance_equipment_count" | ||
) | ||
|
||
def _compute_maintenance_equipment_count(self): | ||
for record in self: | ||
record.maintenance_equipment_count = len(record.maintenance_equipment_ids) | ||
|
||
def action_show_equipments(self): | ||
self.ensure_one() | ||
action = self.env["ir.actions.act_window"]._for_xml_id( | ||
"maintenance.hr_equipment_action" | ||
) | ||
action["context"] = {} | ||
action["domain"] = [("id", "in", self.maintenance_equipment_ids.ids)] | ||
return action |
10 changes: 10 additions & 0 deletions
10
maintenance_equipment_stock/models/stock_production_lot.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Copyright 2023 Dixmit | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import fields, models | ||
|
||
|
||
class StockProductionLot(models.Model): | ||
_inherit = "stock.production.lot" | ||
|
||
equipment_ids = fields.One2many("maintenance.equipment", inverse_name="lot_id") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import test_equipment_from_purchase |
48 changes: 48 additions & 0 deletions
48
maintenance_equipment_stock/tests/test_equipment_from_purchase.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Copyright 2023 Dixmit | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo.tests.common import SavepointCase | ||
|
||
|
||
class TestEquipmentFromPurchase(SavepointCase): | ||
@classmethod | ||
def setUpClass(cls): | ||
super().setUpClass() | ||
cls.partner = cls.env["res.partner"].create({"name": "Demo Partner"}) | ||
cls.product = cls.env["product.template"].create( | ||
{ | ||
"name": "My Product", | ||
"type": "product", | ||
"tracking": "serial", | ||
"maintenance_lot": True, | ||
} | ||
) | ||
cls.purchase = cls.env["purchase.order"].create( | ||
{ | ||
"partner_id": cls.partner.id, | ||
"order_line": [ | ||
( | ||
0, | ||
0, | ||
{ | ||
"product_id": cls.product.product_variant_id.id, | ||
"name": cls.product.name, | ||
}, | ||
) | ||
], | ||
} | ||
) | ||
|
||
def test_equipment_creation(self): | ||
self.purchase.button_confirm() | ||
picking = self.purchase.picking_ids | ||
self.assertTrue(picking) | ||
picking.move_ids_without_package.move_line_ids.write( | ||
{ | ||
"lot_name": "1234", | ||
"qty_done": 1, | ||
} | ||
) | ||
self.assertFalse(picking.maintenance_equipment_ids) | ||
picking.button_validate() | ||
self.assertTrue(picking.maintenance_equipment_ids) |
29 changes: 29 additions & 0 deletions
29
maintenance_equipment_stock/views/maintenance_equipment.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<!-- Copyright 2023 Dixmit | ||
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). --> | ||
<odoo> | ||
|
||
<record model="ir.ui.view" id="maintenance_equipment_form_view"> | ||
<field | ||
name="name" | ||
>maintenance.equipment.form (in maintenance_equipment_stock)</field> | ||
<field name="model">maintenance.equipment</field> | ||
<field name="inherit_id" ref="maintenance.hr_equipment_view_form" /> | ||
<field name="arch" type="xml"> | ||
<field name="serial_no" position="after"> | ||
<field name="lot_id" attrs="{'invisible': [('lot_id', '=', False)]}" /> | ||
<field | ||
name="picking_id" | ||
attrs="{'invisible': [('picking_id', '=', False)]}" | ||
/> | ||
<field | ||
name="purchase_id" | ||
attrs="{'invisible': [('purchase_id', '=', False)]}" | ||
/> | ||
</field> | ||
</field> | ||
</record> | ||
|
||
|
||
|
||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<!-- Copyright 2023 Dixmit | ||
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). --> | ||
<odoo> | ||
|
||
<record model="ir.ui.view" id="product_template_form_view"> | ||
<field | ||
name="name" | ||
>product.template.form (in maintenance_equipment_stock)</field> | ||
<field name="model">product.template</field> | ||
<field name="inherit_id" ref="stock.view_template_property_form" /> | ||
<field name="arch" type="xml"> | ||
<field name="tracking" position="after"> | ||
<field | ||
name="maintenance_lot" | ||
attrs="{'invisible': [('tracking', '!=', 'serial')]}" | ||
/> | ||
</field> | ||
<notebook position="inside"> | ||
<page | ||
name="maintenance" | ||
string="Maintenance" | ||
attrs="{'invisible': ['|','|', ('maintenance_lot', '=', False), ('type', '!=', 'product'), ('tracking', '!=', 'serial')]}" | ||
> | ||
<grpup> | ||
<group> | ||
<field name="maintenance_category_id" /> | ||
<field name="maintenance_team_id" /> | ||
</group> | ||
</grpup> | ||
</page> | ||
</notebook> | ||
</field> | ||
</record> | ||
|
||
|
||
|
||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<!-- Copyright 2023 Dixmit | ||
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). --> | ||
<odoo> | ||
|
||
<record model="ir.ui.view" id="stock_picking_form_view"> | ||
<field name="name">stock.picking.form (in maintenance_equipment_stock)</field> | ||
<field name="model">stock.picking</field> | ||
<field name="inherit_id" ref="stock.view_picking_form" /> | ||
<field name="arch" type="xml"> | ||
<div name="button_box" position="inside"> | ||
<button | ||
name="action_show_equipments" | ||
class="oe_stat_button" | ||
icon="fa-laptop" | ||
type="object" | ||
help="List view of equipments" | ||
attrs="{'invisible': [('maintenance_equipment_count', '=', 0)]}" | ||
> | ||
<div class="o_form_field o_stat_info"> | ||
<span class="o_stat_value"> | ||
<field name="maintenance_equipment_count" /> | ||
</span> | ||
<span class="o_stat_text">Equipment(s)</span> | ||
</div> | ||
</button> | ||
</div> | ||
</field> | ||
</record> | ||
|
||
|
||
|
||
</odoo> |
16 changes: 16 additions & 0 deletions
16
maintenance_equipment_stock/views/stock_production_lot.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<!-- Copyright 2023 Dixmit | ||
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). --> | ||
<odoo> | ||
<!-- | ||
<record model="ir.ui.view" id="stock_production_lot_form_view"> | ||
<field name="name">stock.production.lot.form (in maintenance_equipment_stock)</field> | ||
<field name="model">stock.production.lot</field> | ||
<field name="inherit_id" ref="stock.view_production_lot_form"/> | ||
<field name="arch" type="xml"> | ||
</field> | ||
</record> | ||
--> | ||
|
||
|
||
</odoo> |
1 change: 1 addition & 0 deletions
1
setup/maintenance_equipment_stock/odoo/addons/maintenance_equipment_stock
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../maintenance_equipment_stock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import setuptools | ||
|
||
setuptools.setup( | ||
setup_requires=['setuptools-odoo'], | ||
odoo_addon=True, | ||
) |