Skip to content

Commit

Permalink
Merge PR #27 into 16.0
Browse files Browse the repository at this point in the history
Signed-off-by LoisRForgeFlow
  • Loading branch information
OCA-git-bot committed Jun 17, 2024
2 parents 2ed99f2 + 23f7602 commit 696d944
Show file tree
Hide file tree
Showing 25 changed files with 1,113 additions and 0 deletions.
106 changes: 106 additions & 0 deletions repair_purchase_return/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
======================
Repair Purchase Return
======================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:98b3537e74e31e79bd228a2bcd31227949424adb0cec58b0f5e4168559e53de3
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |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-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/16.0/repair_purchase_return
:alt: OCA/repair
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/repair-16-0/repair-16-0-repair_purchase_return
: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=16.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

The purpose of this module is to add the possibility of create a purchase return order for some repair components products and operations directly from 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:

Description
===========

The purpose of this module is to add the possibility of create a purchase return order for some repair components products and operations directly from repair order.

Usage
=====

#. Go to *Repair > Repair Orders > New* and create a new repair order. Add at least one line in *Parts* (with type *Add* and positive *Quantity*) and *Operations* (with positive *Quantity*).

#. Click *Create Purchase Return* button.

#. On the wizard, choose a valid vendor and click *Create And View Purchase Return* button.

In the *Purchase Return Order*, *Unit Price* of each product line would be the cost price of the product.

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_purchase_return%0Aversion:%2016.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
~~~~~~~~~~~~

* Mateu Griful <[email protected]>
* Lois Rilo <[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-JordiBForgeFlow| image:: https://github.com/JordiBForgeFlow.png?size=40px
:target: https://github.com/JordiBForgeFlow
:alt: JordiBForgeFlow

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-JordiBForgeFlow|

This module is part of the `OCA/repair <https://github.com/OCA/repair/tree/16.0/repair_purchase_return>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 2 additions & 0 deletions repair_purchase_return/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import models
from . import wizards
23 changes: 23 additions & 0 deletions repair_purchase_return/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright (C) 2021 ForgeFlow S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)

{
"name": "Repair Purchase Return",
"version": "16.0.1.0.0",
"development_status": "Alpha",
"license": "LGPL-3",
"category": "Repair",
"summary": "Create a Purchase Return from a Repair",
"author": "ForgeFlow, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/repair",
"depends": ["repair", "purchase_return"],
"data": [
"security/ir.model.access.csv",
"wizards/repair_purchase_return_wiz_views.xml",
"views/repair_order_views.xml",
"views/purchase_return_order_views.xml",
],
"maintainers": ["JordiBForgeFlow"],
"installable": True,
"application": False,
}
5 changes: 5 additions & 0 deletions repair_purchase_return/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from . import repair_order
from . import repair_line
from . import repair_fee
from . import purchase_return_order_line
from . import purchase_return_order
48 changes: 48 additions & 0 deletions repair_purchase_return/models/purchase_return_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Copyright (C) 2021 ForgeFlow S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)

from odoo import api, fields, models


class PurchaseReturnOrder(models.Model):
_inherit = "purchase.return.order"

repair_order_count = fields.Integer(
compute="_compute_repair_orders",
string="Repair Orders Count",
)
repair_order_ids = fields.Many2many(
comodel_name="repair.order",
compute="_compute_repair_orders",
)

@api.depends(
"order_line.repair_line_ids.repair_id",
"order_line.repair_fee_ids.repair_id",
)
def _compute_repair_orders(self):
for rec in self:
repair_orders = rec.order_line.mapped("repair_line_ids.repair_id")
repair_orders |= rec.order_line.mapped("repair_fee_ids.repair_id")
rec.repair_order_ids = repair_orders
rec.repair_order_count = len(repair_orders)

def action_view_repair_orders(self):
repair_orders = self.mapped("repair_order_ids")
action = self.env["ir.actions.actions"]._for_xml_id(
"repair.action_repair_order_tree"
)
if len(repair_orders) > 1:
action["domain"] = [("id", "in", repair_orders.ids)]
elif len(repair_orders) == 1:
form_view = [(self.env.ref("repair.view_repair_order_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"] = repair_orders.id
else:
action = {"type": "ir.actions.act_window_close"}
return action
11 changes: 11 additions & 0 deletions repair_purchase_return/models/purchase_return_order_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Copyright (C) 2021 ForgeFlow S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)

from odoo import fields, models


class PurchaseReturnOrderLine(models.Model):
_inherit = "purchase.return.order.line"

repair_line_ids = fields.Many2many(comodel_name="repair.line", copy=False)
repair_fee_ids = fields.Many2many(comodel_name="repair.fee", copy=False)
46 changes: 46 additions & 0 deletions repair_purchase_return/models/repair_fee.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Copyright (C) 2021 ForgeFlow S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)

from odoo import api, fields, models


class RepairFee(models.Model):
_inherit = "repair.fee"

purchase_return_line_ids = fields.Many2many(
comodel_name="purchase.return.order.line", copy=False
)

@api.model
def _get_purchase_return_line_onchange_product_fields(self):
return ["price_unit", "taxes_id", "refund_only"]

@api.model
def _execute_purchase_return_line_onchange(self, vals):
cls = self.env["purchase.return.order.line"]
onchanges_dict = {
"onchange_product_id": self._get_purchase_return_line_onchange_product_fields()
}
for onchange_method, changed_fields in onchanges_dict.items():
if any(f not in vals for f in changed_fields):
obj = cls.new(vals)
getattr(obj, onchange_method)()
for field in changed_fields:
vals[field] = obj._fields[field].convert_to_write(obj[field], obj)

@api.model
def _prepare_purchase_order_line_vals(self, pro):
vals = {
"name": self.name,
"order_id": pro.id,
"product_id": self.product_id.id,
"product_uom": self.product_uom.id,
"price_unit": 0.0,
"product_qty": self.product_uom_qty,
"repair_fee_ids": [(4, self.id)],
"date_planned": fields.Datetime.now(),
"refund_only": True,
"display_type": "product",
}
self._execute_purchase_return_line_onchange(vals)
return vals
46 changes: 46 additions & 0 deletions repair_purchase_return/models/repair_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Copyright (C) 2021 ForgeFlow S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)

from odoo import api, fields, models


class RepairLine(models.Model):
_inherit = "repair.line"

purchase_return_line_ids = fields.Many2many(
comodel_name="purchase.return.order.line", copy=False
)

@api.model
def _get_purchase_return_line_onchange_product_fields(self):
return ["price_unit", "taxes_id", "refund_only"]

@api.model
def _execute_purchase_return_line_onchange(self, vals):
cls = self.env["purchase.return.order.line"]
onchanges_dict = {
"onchange_product_id": self._get_purchase_return_line_onchange_product_fields()
}
for onchange_method, changed_fields in onchanges_dict.items():
if any(f not in vals for f in changed_fields):
obj = cls.new(vals)
getattr(obj, onchange_method)()
for field in changed_fields:
vals[field] = obj._fields[field].convert_to_write(obj[field], obj)

@api.model
def _prepare_purchase_order_line_vals(self, pro):
vals = {
"name": self.name,
"order_id": pro.id,
"product_id": self.product_id.id,
"product_uom": self.product_uom.id,
"price_unit": 0.0,
"product_qty": self.product_uom_qty,
"repair_line_ids": [(4, self.id)],
"date_planned": fields.Datetime.now(),
"refund_only": True,
"display_type": "product",
}
self._execute_purchase_return_line_onchange(vals)
return vals
Loading

0 comments on commit 696d944

Please sign in to comment.