-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] repair_procurement: new module to create procurements from repa…
…ir orders if there is no stock available in source location
- Loading branch information
Showing
19 changed files
with
907 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,89 @@ | ||
================== | ||
Repair Procurement | ||
================== | ||
|
||
.. | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! source digest: sha256:a555c3d246cb5f50375fdce26f280d36e1f722ecb37c627bba1ca84f71f82fc6 | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png | ||
:target: https://odoo-community.org/page/development-status | ||
:alt: Beta | ||
.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png | ||
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html | ||
:alt: License: LGPL-3 | ||
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Frepair-lightgray.png?logo=github | ||
:target: https://github.com/OCA/repair/tree/15.0/repair_procurement | ||
:alt: OCA/repair | ||
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png | ||
:target: https://translation.odoo-community.org/projects/repair-15-0/repair-15-0-repair_procurement | ||
:alt: Translate me on Weblate | ||
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png | ||
:target: https://runboat.odoo-community.org/builds?repo=OCA/repair&target_branch=15.0 | ||
:alt: Try me on Runboat | ||
|
||
|badge1| |badge2| |badge3| |badge4| |badge5| | ||
|
||
This module generates a procurement of the parts required from source location | ||
when a repair order is confirmed. | ||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Usage | ||
===== | ||
|
||
Create a repair order with parts required and define source location. | ||
|
||
Confirm the repair order. | ||
|
||
If the product is not available in source location a procurement will be created. | ||
Depending on the routes configuration it could trigger a purchase order, manufacture order or a transfer. | ||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues <https://github.com/OCA/repair/issues>`_. | ||
In case of trouble, please check there if your issue has already been reported. | ||
If you spotted it first, help us to smash it by providing a detailed and welcomed | ||
`feedback <https://github.com/OCA/repair/issues/new?body=module:%20repair_procurement%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. | ||
|
||
Do not contact contributors directly about support or help with technical issues. | ||
|
||
Credits | ||
======= | ||
|
||
Authors | ||
~~~~~~~ | ||
|
||
* Jarsa | ||
|
||
Contributors | ||
~~~~~~~~~~~~ | ||
|
||
* `Jarsa <https://www.jarsa.com.mx>`_ | ||
|
||
* Alan Ramos <[email protected]> | ||
|
||
Maintainers | ||
~~~~~~~~~~~ | ||
|
||
This module is maintained by the OCA. | ||
|
||
.. image:: https://odoo-community.org/logo.png | ||
:alt: Odoo Community Association | ||
:target: https://odoo-community.org | ||
|
||
OCA, or the Odoo Community Association, is a nonprofit organization whose | ||
mission is to support the collaborative development of Odoo features and | ||
promote its widespread use. | ||
|
||
This module is part of the `OCA/repair <https://github.com/OCA/repair/tree/15.0/repair_procurement>`_ project on GitHub. | ||
|
||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. |
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 @@ | ||
# Copyright 2021 Jarsa | ||
# License LGPL-3 - See http://www.gnu.org/licenses/lgpl-3.0.html | ||
|
||
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,15 @@ | ||
# Copyright 2021 Jarsa | ||
# License LGPL-3 - See http://www.gnu.org/licenses/lgpl-3.0.html | ||
|
||
{ | ||
"name": "Repair Procurement", | ||
"version": "15.0.1.0.0", | ||
"category": "Repair", | ||
"summary": "Create a procurement when a repair order is confirmed.", | ||
"author": "Jarsa, Odoo Community Association (OCA)", | ||
"website": "https://github.com/OCA/repair", | ||
"license": "LGPL-3", | ||
"depends": ["repair"], | ||
"data": ["views/repair_order_view.xml"], | ||
"installable": 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,97 @@ | ||
# Translation of Odoo Server. | ||
# This file contains the translation of the following modules: | ||
# * repair_procurement | ||
# | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: Odoo Server 14.0+e\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"POT-Creation-Date: 2021-01-20 22:14+0000\n" | ||
"PO-Revision-Date: 2021-01-20 16:14-0600\n" | ||
"Last-Translator: Jesús Alan Ramos Rodríguez <[email protected]>\n" | ||
"Language-Team: \n" | ||
"MIME-Version: 1.0\n" | ||
"Content-Type: text/plain; charset=UTF-8\n" | ||
"Content-Transfer-Encoding: 8bit\n" | ||
"Plural-Forms: \n" | ||
"Language: es\n" | ||
"X-Generator: Poedit 2.4.2\n" | ||
|
||
#. module: repair_procurement | ||
#: model:ir.model.fields,field_description:repair_procurement.field_repair_order__picking_count | ||
msgid "Delivery Orders" | ||
msgstr "Albaranes de salida" | ||
|
||
#. module: repair_procurement | ||
#: model:ir.model.fields,field_description:repair_procurement.field_procurement_group__display_name | ||
#: model:ir.model.fields,field_description:repair_procurement.field_repair_line__display_name | ||
#: model:ir.model.fields,field_description:repair_procurement.field_repair_order__display_name | ||
#: model:ir.model.fields,field_description:repair_procurement.field_stock_move__display_name | ||
#: model:ir.model.fields,field_description:repair_procurement.field_stock_picking__display_name | ||
#: model:ir.model.fields,field_description:repair_procurement.field_stock_rule__display_name | ||
msgid "Display Name" | ||
msgstr "Nombre mostrado" | ||
|
||
#. module: repair_procurement | ||
#: model:ir.model.fields,field_description:repair_procurement.field_procurement_group__id | ||
#: model:ir.model.fields,field_description:repair_procurement.field_repair_line__id | ||
#: model:ir.model.fields,field_description:repair_procurement.field_repair_order__id | ||
#: model:ir.model.fields,field_description:repair_procurement.field_stock_move__id | ||
#: model:ir.model.fields,field_description:repair_procurement.field_stock_picking__id | ||
#: model:ir.model.fields,field_description:repair_procurement.field_stock_rule__id | ||
msgid "ID" | ||
msgstr "" | ||
|
||
#. module: repair_procurement | ||
#: model:ir.model.fields,field_description:repair_procurement.field_procurement_group____last_update | ||
#: model:ir.model.fields,field_description:repair_procurement.field_repair_line____last_update | ||
#: model:ir.model.fields,field_description:repair_procurement.field_repair_order____last_update | ||
#: model:ir.model.fields,field_description:repair_procurement.field_stock_move____last_update | ||
#: model:ir.model.fields,field_description:repair_procurement.field_stock_picking____last_update | ||
#: model:ir.model.fields,field_description:repair_procurement.field_stock_rule____last_update | ||
msgid "Last Modified on" | ||
msgstr "Última modificación el" | ||
|
||
#. module: repair_procurement | ||
#: model:ir.model.fields,field_description:repair_procurement.field_repair_order__picking_ids | ||
#: model_terms:ir.ui.view,arch_db:repair_procurement.repair_order_form | ||
msgid "Pickings" | ||
msgstr "Albaranes" | ||
|
||
#. module: repair_procurement | ||
#: model:ir.model,name:repair_procurement.model_procurement_group | ||
#: model:ir.model.fields,field_description:repair_procurement.field_repair_order__procurement_group_id | ||
msgid "Procurement Group" | ||
msgstr "Grupo de abastecimiento" | ||
|
||
#. module: repair_procurement | ||
#: model:ir.model.fields,field_description:repair_procurement.field_stock_move__repair_line_id | ||
msgid "Repair Line" | ||
msgstr "Línea de reparación" | ||
|
||
#. module: repair_procurement | ||
#: model:ir.model,name:repair_procurement.model_repair_line | ||
msgid "Repair Line (parts)" | ||
msgstr "Línea de Reparación (partes)" | ||
|
||
#. module: repair_procurement | ||
#: model:ir.model,name:repair_procurement.model_repair_order | ||
#: model:ir.model.fields,field_description:repair_procurement.field_procurement_group__repair_id | ||
#: model:ir.model.fields,field_description:repair_procurement.field_stock_picking__repair_id | ||
msgid "Repair Order" | ||
msgstr "Orden de reparación" | ||
|
||
#. module: repair_procurement | ||
#: model:ir.model,name:repair_procurement.model_stock_move | ||
msgid "Stock Move" | ||
msgstr "Movimiento de existencias" | ||
|
||
#. module: repair_procurement | ||
#: model:ir.model,name:repair_procurement.model_stock_rule | ||
msgid "Stock Rule" | ||
msgstr "Regla de Inventario" | ||
|
||
#. module: repair_procurement | ||
#: model:ir.model,name:repair_procurement.model_stock_picking | ||
msgid "Transfer" | ||
msgstr "Albarán" |
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,8 @@ | ||
# Copyright 2021 Jarsa | ||
# License LGPL-3 - See http://www.gnu.org/licenses/lgpl-3.0.html | ||
|
||
from . import repair_order | ||
from . import procurement_group | ||
from . import stock_move | ||
from . import stock_picking | ||
from . import stock_rule |
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 2021 Jarsa | ||
# License LGPL-3 - See http://www.gnu.org/licenses/lgpl-3.0.html | ||
|
||
from odoo import fields, models | ||
|
||
|
||
class ProcurementGroup(models.Model): | ||
_inherit = "procurement.group" | ||
|
||
repair_id = fields.Many2one("repair.order", "Repair Order") |
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,120 @@ | ||
# Copyright 2021 Jarsa | ||
# License LGPL-3 - See http://www.gnu.org/licenses/lgpl-3.0.html | ||
|
||
from odoo import api, fields, models | ||
from odoo.tools import float_compare | ||
|
||
|
||
class RepairOrder(models.Model): | ||
_inherit = "repair.order" | ||
|
||
procurement_group_id = fields.Many2one("procurement.group", copy=False) | ||
picking_ids = fields.One2many("stock.picking", "repair_id", string="Pickings") | ||
picking_count = fields.Integer( | ||
string="Delivery Orders", compute="_compute_picking_count" | ||
) | ||
|
||
@api.depends("picking_ids") | ||
def _compute_picking_count(self): | ||
for order in self: | ||
order.picking_count = len(order.picking_ids) | ||
|
||
def action_view_pickings(self): | ||
action = self.env["ir.actions.actions"]._for_xml_id( | ||
"stock.action_picking_tree_all" | ||
) | ||
|
||
pickings = self.mapped("picking_ids") | ||
if len(pickings) > 1: | ||
action["domain"] = [("id", "in", pickings.ids)] | ||
elif pickings: | ||
form_view = [(self.env.ref("stock.view_picking_form").id, "form")] | ||
if "views" in action: | ||
action["views"] = form_view + [ | ||
(state, view) for state, view in action["views"] if view != "form" | ||
] | ||
else: | ||
action["views"] = form_view | ||
action["res_id"] = pickings.id | ||
action["context"] = dict( | ||
self._context, | ||
default_picking_type_id=pickings[0].picking_type_id.id, | ||
default_origin=self.name, | ||
default_group_id=pickings[0].group_id.id, | ||
) | ||
return action | ||
|
||
def action_validate(self): | ||
precision = self.env["decimal.precision"].precision_get( | ||
"Product Unit of Measure" | ||
) | ||
procurements = [] | ||
for line in self.mapped("operations"): | ||
if line.product_id.type in ("consu", "service"): | ||
continue | ||
available_qty = self.env["stock.quant"]._get_available_quantity( | ||
line.product_id, line.location_id, strict=True | ||
) | ||
repair_qty = line.product_uom._compute_quantity( | ||
line.product_uom_qty, line.product_id.uom_id | ||
) | ||
if ( | ||
float_compare(available_qty, repair_qty, precision_digits=precision) | ||
== 1 | ||
): | ||
continue | ||
group = line._get_procurement_group() | ||
values = line._prepare_procurement_values(group_id=group) | ||
product_qty, procurement_uom = line.product_uom._adjust_uom_quantities( | ||
line.product_uom_qty, line.product_id.uom_id | ||
) | ||
procurements.append( | ||
self.env["procurement.group"].Procurement( | ||
line.product_id, | ||
product_qty, | ||
procurement_uom, | ||
line.location_id, | ||
line.name, | ||
line.repair_id.name, | ||
line.repair_id.company_id, | ||
values, | ||
) | ||
) | ||
if procurements: | ||
self.env["procurement.group"].run(procurements) | ||
return super().action_validate() | ||
|
||
def action_repair_cancel(self): | ||
self.picking_ids.filtered( | ||
lambda p: p.state not in ["cancel", "done"] | ||
).action_cancel() | ||
return super().action_repair_cancel() | ||
|
||
|
||
class RepairOrderLine(models.Model): | ||
_inherit = "repair.line" | ||
|
||
def _get_procurement_group(self): | ||
self.ensure_one() | ||
if not self.repair_id.procurement_group_id: | ||
group = self.env["procurement.group"].create( | ||
self._prepare_procurement_group_vals() | ||
) | ||
self.repair_id.procurement_group_id = group | ||
return self.repair_id.procurement_group_id | ||
|
||
def _prepare_procurement_group_vals(self): | ||
self.ensure_one() | ||
return { | ||
"name": self.repair_id.name, | ||
"move_type": "direct", | ||
"repair_id": self.repair_id.id, | ||
} | ||
|
||
def _prepare_procurement_values(self, group_id=False): | ||
self.ensure_one() | ||
return { | ||
"group_id": group_id, | ||
"repair_line_id": self.id, | ||
"warehouse_id": self.location_id.warehouse_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,10 @@ | ||
# Copyright 2021 Jarsa | ||
# License LGPL-3 - See http://www.gnu.org/licenses/lgpl-3.0.html | ||
|
||
from odoo import fields, models | ||
|
||
|
||
class StockMove(models.Model): | ||
_inherit = "stock.move" | ||
|
||
repair_line_id = fields.Many2one("repair.line", index=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 2021 Jarsa | ||
# License LGPL-3 - See http://www.gnu.org/licenses/lgpl-3.0.html | ||
|
||
from odoo import fields, models | ||
|
||
|
||
class StockPicking(models.Model): | ||
_inherit = "stock.picking" | ||
|
||
repair_id = fields.Many2one( | ||
related="group_id.repair_id", string="Repair Order", store=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,13 @@ | ||
# Copyright 2021 Jarsa | ||
# License LGPL-3 - See http://www.gnu.org/licenses/lgpl-3.0.html | ||
|
||
from odoo import models | ||
|
||
|
||
class StockRule(models.Model): | ||
_inherit = "stock.rule" | ||
|
||
def _get_custom_move_fields(self): | ||
fields = super()._get_custom_move_fields() | ||
fields += ["repair_line_id"] | ||
return fields |
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,3 @@ | ||
* `Jarsa <https://www.jarsa.com.mx>`_ | ||
|
||
* Alan Ramos <[email protected]> |
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,2 @@ | ||
This module generates a procurement of the parts required from source location | ||
when a repair order is confirmed. |
Oops, something went wrong.