-
-
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.
Signed-off-by LoisRForgeFlow
- Loading branch information
Showing
20 changed files
with
1,068 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,104 @@ | ||
==================== | ||
Repair To Sale Order | ||
==================== | ||
|
||
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png | ||
:target: https://odoo-community.org/page/development-status | ||
:alt: Alpha | ||
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png | ||
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html | ||
:alt: License: AGPL-3 | ||
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fmanufacture-lightgray.png?logo=github | ||
:target: https://github.com/OCA/manufacture/tree/14.0/repair_sale_order | ||
:alt: OCA/manufacture | ||
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png | ||
:target: https://translation.odoo-community.org/projects/manufacture-14-0/manufacture-14-0-repair_sale_order | ||
:alt: Translate me on Weblate | ||
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png | ||
:target: https://runbot.odoo-community.org/runbot/129/14.0 | ||
:alt: Try me on Runbot | ||
|
||
|badge1| |badge2| |badge3| |badge4| |badge5| | ||
|
||
This module add possibility to create a sale order for spare parts on repair order | ||
|
||
|
||
.. IMPORTANT:: | ||
This is an alpha version, the data model and design can change at any time without warning. | ||
Only for development or testing purpose, do not use in production. | ||
`More details on development status <https://odoo-community.org/page/development-status>`_ | ||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Usage | ||
===== | ||
|
||
On Repairs / Configuration / Repair Type you can set active Create Sale Order | ||
this change behavior of repair form and can create Sales Order from Repair Order | ||
|
||
Your repair order will change to Done status when Sales Orders related confirmed, | ||
if Sales Order Canceled, Repair Order will set as Confirmed | ||
|
||
Known issues / Roadmap | ||
====================== | ||
|
||
Possible improvements for future versions: | ||
|
||
* The main use case is for make spare parts sell from repair orders, | ||
we need a way to support cases when we can send freely spare parts to customer | ||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues <https://github.com/OCA/manufacture/issues>`_. | ||
In case of trouble, please check there if your issue has already been reported. | ||
If you spotted it first, help us smashing it by providing a detailed and welcomed | ||
`feedback <https://github.com/OCA/manufacture/issues/new?body=module:%20repair_sale_order%0Aversion:%2014.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 | ||
~~~~~~~ | ||
|
||
* ForgeFlow | ||
|
||
Contributors | ||
~~~~~~~~~~~~ | ||
|
||
* Christopher Ormaza <[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. | ||
|
||
.. |maintainer-ChrisOForgeFlow| image:: https://github.com/ChrisOForgeFlow.png?size=40px | ||
:target: https://github.com/ChrisOForgeFlow | ||
:alt: ChrisOForgeFlow | ||
|
||
Current `maintainer <https://odoo-community.org/page/maintainer-role>`__: | ||
|
||
|maintainer-ChrisOForgeFlow| | ||
|
||
This module is part of the `OCA/manufacture <https://github.com/OCA/manufacture/tree/14.0/repair_sale_order>`_ 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 @@ | ||
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,22 @@ | ||
# Copyright 2022 ForgeFlow S.L. (https://forgeflow.com) | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). | ||
|
||
{ | ||
"name": "Repair To Sale Order", | ||
"version": "16.0.1.0.0", | ||
"author": "ForgeFlow, Odoo Community Association (OCA)", | ||
"website": "https://github.com/OCA/repair", | ||
"summary": "Repair To Sale Order", | ||
"category": "Repair", | ||
"depends": ["repair", "repair_type", "sale", "sales_team"], | ||
"data": [ | ||
"views/repair_order_view.xml", | ||
"views/sale_order_view.xml", | ||
"views/repair_type_view.xml", | ||
], | ||
"installable": True, | ||
"development_status": "Alpha", | ||
"license": "AGPL-3", | ||
"maintainers": ["ChrisOForgeFlow"], | ||
"application": False, | ||
} |
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 @@ | ||
from . import repair_order | ||
from . import sale_order | ||
from . import repair_type | ||
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,104 @@ | ||
# Copyright 2022 ForgeFlow S.L. (https://forgeflow.com) | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). | ||
from odoo import _, fields, models | ||
from odoo.exceptions import UserError | ||
|
||
|
||
class RepairOrder(models.Model): | ||
|
||
_inherit = "repair.order" | ||
|
||
create_sale_order = fields.Boolean(related="repair_type_id.create_sale_order") | ||
sale_order_ids = fields.Many2many( | ||
comodel_name="sale.order", | ||
string="Sale orders", | ||
compute="_compute_sale_order", | ||
) | ||
sale_order_count = fields.Integer( | ||
string="Sale order count", | ||
compute="_compute_sale_order", | ||
) | ||
|
||
def _compute_sale_order(self): | ||
for rec in self: | ||
rec.sale_order_ids = rec.mapped("operations.sale_line_id.order_id").ids | ||
rec.sale_order_count = len(rec.sale_order_ids) | ||
|
||
def action_show_sales_order(self, new_orders=False): | ||
action = self.env["ir.actions.actions"]._for_xml_id("sale.action_quotations") | ||
form_view = [(self.env.ref("sale.view_order_form").id, "form")] | ||
orders = new_orders | ||
if not new_orders: | ||
orders = self.mapped("sale_order_ids") | ||
if len(orders) == 1: | ||
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"] = orders.ids[0] | ||
else: | ||
action["domain"] = [("id", "in", orders.ids)] | ||
return action | ||
|
||
def _get_sale_order_data(self): | ||
self.ensure_one() | ||
addresses = self.partner_id.address_get(["delivery"]) | ||
self.address_id = addresses["delivery"] | ||
res = { | ||
"partner_id": self.partner_id.id, | ||
"partner_shipping_id": self.address_id.id, | ||
"origin": self.display_name, | ||
"note": self.quotation_notes, | ||
} | ||
return res | ||
|
||
def action_create_sale_order(self): | ||
order_model = self.env["sale.order"].sudo() | ||
order_line_model = self.env["sale.order.line"].sudo() | ||
orders = order_model.browse() | ||
for rec in self.filtered( | ||
lambda x: not x.sale_order_ids and x.create_sale_order | ||
): | ||
sale_order_data = rec._get_sale_order_data() | ||
sale_order = order_model.create(sale_order_data) | ||
orders |= sale_order | ||
self.onchange_partner_id() | ||
for line in rec.operations: | ||
sale_order_line = order_line_model.create( | ||
line._get_sale_line_data(sale_order) | ||
) | ||
line.sale_line_id = sale_order_line.id | ||
return self.action_show_sales_order(orders) | ||
|
||
def action_validate(self): | ||
if self.filtered(lambda x: x.create_sale_order and not x.operations): | ||
raise UserError( | ||
_( | ||
"You should input at least one part line to" | ||
" continue on create Sales Order from Repair Order" | ||
) | ||
) | ||
return super().action_validate() | ||
|
||
|
||
class RepairLine(models.Model): | ||
|
||
_inherit = "repair.line" | ||
|
||
def _get_sale_line_data(self, sale_order): | ||
self.ensure_one() | ||
res = { | ||
"product_id": self.product_id.id, | ||
"name": self.name, | ||
"product_uom_qty": self.product_uom_qty, | ||
"price_unit": self.price_unit, | ||
"tax_id": self.tax_id and [(6, 0, self.tax_id.ids)] or [], | ||
"order_id": sale_order.id, | ||
} | ||
return res | ||
|
||
sale_line_id = fields.Many2one( | ||
comodel_name="sale.order.line", string="Sale line", copy=False | ||
) |
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 2022 ForgeFlow S.L. (https://forgeflow.com) | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). | ||
from odoo import fields, models | ||
|
||
|
||
class RepairType(models.Model): | ||
|
||
_inherit = "repair.type" | ||
|
||
create_sale_order = fields.Boolean( | ||
string="Create sale order?", | ||
default=False, | ||
) |
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,94 @@ | ||
# Copyright 2022 ForgeFlow S.L. (https://forgeflow.com) | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). | ||
from odoo import fields, models | ||
from odoo.tools.safe_eval import safe_eval | ||
|
||
|
||
class SaleOrder(models.Model): | ||
|
||
_inherit = "sale.order" | ||
|
||
repair_order_ids = fields.Many2many( | ||
comodel_name="repair.order", | ||
string="Repair orders", | ||
compute="_compute_repair_order", | ||
) | ||
repair_order_count = fields.Integer( | ||
string="Repair orders count", | ||
compute="_compute_repair_order", | ||
) | ||
|
||
def _compute_repair_order(self): | ||
for rec in self: | ||
rec.repair_order_ids = rec.mapped( | ||
"order_line.repair_line_ids.repair_id" | ||
).ids | ||
rec.repair_order_count = len(rec.repair_order_ids) | ||
|
||
def action_show_repair_order(self): | ||
action = self.env["ir.actions.actions"]._for_xml_id( | ||
"repair.action_repair_order_tree" | ||
) | ||
form_view = [(self.env.ref("repair.view_repair_order_form").id, "form")] | ||
orders = self.mapped("repair_order_ids") | ||
if len(orders) == 1: | ||
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"] = orders.ids[0] | ||
else: | ||
action["domain"] += [("id", "in", orders.ids)] | ||
domain = safe_eval(action["domain"]) or [] | ||
domain += [("id", "in", orders.ids)] | ||
action["domain"] = action["domain"] | ||
return action | ||
|
||
def _change_repair_order_status_done(self): | ||
for repair_order in self.mapped("repair_order_ids"): | ||
repair_order.write( | ||
{ | ||
"state": "done", | ||
} | ||
) | ||
|
||
def _change_repair_order_status_confirmed(self): | ||
for repair_order in self.mapped("repair_order_ids"): | ||
repair_order.write( | ||
{ | ||
"state": "confirmed", | ||
} | ||
) | ||
|
||
def action_confirm(self): | ||
res = super().action_confirm() | ||
self._change_repair_order_status_done() | ||
return res | ||
|
||
def action_cancel(self): | ||
res = super().action_cancel() | ||
self._change_repair_order_status_confirmed() | ||
return res | ||
|
||
|
||
class SaleOrderLine(models.Model): | ||
|
||
_inherit = "sale.order.line" | ||
|
||
repair_line_ids = fields.One2many( | ||
comodel_name="repair.line", | ||
inverse_name="sale_line_id", | ||
string="Repair lines", | ||
required=False, | ||
) | ||
|
||
def _prepare_procurement_values(self, group_id=False): | ||
res = super()._prepare_procurement_values(group_id) | ||
res.update( | ||
{ | ||
"repair_ids": self.repair_line_ids.mapped("repair_id.id"), | ||
} | ||
) | ||
return res |
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 ForgeFlow S.L. (https://forgeflow.com) | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). | ||
|
||
from odoo import models | ||
|
||
|
||
class StockRule(models.Model): | ||
_inherit = "stock.rule" | ||
|
||
def _get_stock_move_values( | ||
self, | ||
product_id, | ||
product_qty, | ||
product_uom, | ||
location_dest_id, | ||
name, | ||
origin, | ||
company_id, | ||
values, | ||
): | ||
res = super()._get_stock_move_values( | ||
product_id, | ||
product_qty, | ||
product_uom, | ||
location_dest_id, | ||
name, | ||
origin, | ||
company_id, | ||
values, | ||
) | ||
repair_ids = values.get("repair_ids", False) | ||
if repair_ids: | ||
res.update( | ||
{ | ||
"repair_id": repair_ids[0], | ||
} | ||
) | ||
return res |
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 @@ | ||
* Christopher Ormaza <[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 @@ | ||
This module add possibility to create a sale order for spare parts on 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,4 @@ | ||
Possible improvements for future versions: | ||
|
||
* The main use case is for make spare parts sell from repair orders, | ||
we need a way to support cases when we can send freely spare parts to customer |
Oops, something went wrong.