Skip to content

Commit

Permalink
[MIG] sale_rental from v12 to v14
Browse files Browse the repository at this point in the history
No more need to add users to the packaging group
View of rental group is now possible on product.template form view
  • Loading branch information
alexis-via committed Dec 6, 2021
1 parent 9367950 commit ac64654
Show file tree
Hide file tree
Showing 24 changed files with 223 additions and 257 deletions.
108 changes: 1 addition & 107 deletions sale_rental/README.rst
Original file line number Diff line number Diff line change
@@ -1,107 +1 @@
===========
Sale Rental
===========

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |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-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%2Fsale--workflow-lightgray.png?logo=github
:target: https://github.com/OCA/sale-workflow/tree/12.0/sale_rental
:alt: OCA/sale-workflow
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/sale-workflow-12-0/sale-workflow-12-0-sale_rental
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/167/12.0
:alt: Try me on Runbot

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

With this module, you can rent products with Odoo. This module supports:

* regular rentals.
* rental extensions.
* sale of rented products.

**Table of contents**

.. contents::
:local:

Configuration
=============

In the menu *Sales > Products > Product Variants*, on the form view of a stockable product or consumable, in the *Sales* tab, there is a button *Create Rental Service* which starts a wizard to generate the corresponding rental service.

In the menu *Inventory > Configuration > Warehouse Management > Warehouses*, on the form view of the warehouse, in the *Technical Information* tab, you will see two additional stock locations: *Rental In* (stock of products to rent) and *Rental Out* (products currently rented). In the *Warehouse Configuration* tab, make sure that the option *Rental Allowed* is checked.

To use the module, you need to have access to the form view of sale order lines. For that, users must be part of the group *Manage Product Packaging*. To add all your users to that group, go to the menu *Inventory > Configuration > Settings*: in the *Products* section, enable the option *Product Packagings* and click on *Save* (this is done for you upon module installation).

Usage
=====

In a sale order line (form view, not tree view), if you select a rental service, you can :

* create a new rental with a start date and an end date: when the sale order is confirmed, it will generate a delivery order and an incoming shipment.
* extend an existing rental: the incoming shipment will be postponed to the end date of the extension.

In a sale order line, if you select a product that has a corresponding rental service, you can decide to sell the rented product that the customer already has. If the sale order is confirmed, the incoming shipment will be cancelled and a new delivery order will be created with a stock move from *Rental Out* to *Customers*.

Known issues / Roadmap
======================

This module has the following limitations:

* No support for planning/agenda of the rented products (i.e. you can't rely on this module to check your capacity to rent a product for the selected dates when you create a quote)
* The unit of measure of the rental services must be *Day* (the rental per hour / per week / per month is not supported for the moment)

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/sale-workflow/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/sale-workflow/issues/new?body=module:%20sale_rental%0Aversion:%2012.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
~~~~~~~

* Akretion
* Sodexis

Contributors
~~~~~~~~~~~~

* Alexis de Lattre <[email protected]>
* Sodexis <[email protected]>
* Danh Vo <https://github.com/danhvophuong>

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/sale-workflow <https://github.com/OCA/sale-workflow/tree/12.0/sale_rental>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
Will be regenerated from readme subdir
1 change: 0 additions & 1 deletion sale_rental/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
from .hooks import add_to_group_stock_packaging
from . import models
from . import wizard
8 changes: 4 additions & 4 deletions sale_rental/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
# Copyright 2014-2019 Akretion France (http://www.akretion.com)
# Copyright 2014-2021 Akretion France (http://www.akretion.com)
# @author Alexis de Lattre <[email protected]>
# Copyright 2016-2019 Sodexis (http://sodexis.com)
# Copyright 2016-2021 Sodexis (http://sodexis.com)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
'name': 'Sale Rental',
'version': '12.0.1.1.0',
'version': '14.0.1.0.0',
'category': 'Sales',
'license': 'AGPL-3',
'summary': 'Manage Rental of Products',
'author': 'Akretion, Sodexis, Odoo Community Association (OCA)',
'maintainers': ['alexis-via'],
'website': 'https://github.com/OCA/sale-workflow',
'depends': ['sale_start_end_dates', 'sale_stock', 'sales_team'],
'data': [
Expand All @@ -22,7 +23,6 @@
'wizard/create_rental_product_view.xml',
'views/product.xml',
],
'post_init_hook': 'add_to_group_stock_packaging',
'demo': ['demo/rental_demo.xml'],
'installable': True,
}
4 changes: 2 additions & 2 deletions sale_rental/data/rental_data.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2014-2019 Akretion France (http://www.akretion.com/)
Copyright 2014-2021 Akretion France (http://www.akretion.com/)
@author Alexis de Lattre <[email protected]>
Copyright 2016-2019 Sodexis
Copyright 2016-2021 Sodexis
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->

Expand Down
8 changes: 2 additions & 6 deletions sale_rental/demo/rental_demo.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2014-2019 Akretion France (http://www.akretion.com/)
Copyright 2014-2021 Akretion France (http://www.akretion.com/)
@author Alexis de Lattre <[email protected]>
Copyright 2016-2019 Sodexis
Copyright 2016-2021 Sodexis
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->

Expand Down Expand Up @@ -56,15 +56,11 @@
<!-- Create inventory on Rental In for these products -->
<record id="rental_inventory" model="stock.inventory">
<field name="name">Inventory for rented products</field>
<field name="filter">partial</field>
</record>

<function model="stock.inventory" name="create_demo_and_validate">
<function eval="[[('id', '=', ref('rental_inventory'))]]" model="stock.inventory" name="search"/>
</function>

<record id="base.user_demo" model="res.users">
<field name="groups_id" eval="[(4, ref('product.group_product_variant'))]"/>
</record>

</odoo>
13 changes: 0 additions & 13 deletions sale_rental/hooks.py

This file was deleted.

2 changes: 1 addition & 1 deletion sale_rental/i18n/fr.po
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ msgstr ""
#: model:product.template,name:sale_rental.rent_product_product_20_product_template
#, fuzzy
msgid "Rental of one Flipover"
msgstr "Location d'un %s"
msgstr "Location d'un Flipover"

#. module: sale_rental
#: model:product.product,name:sale_rental.rent_consu_delivery_01
Expand Down
4 changes: 3 additions & 1 deletion sale_rental/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from . import product
from . import sale_order
from . import sale_rental
from . import stock
from . import stock_warehouse
from . import stock_rule
from . import stock_inventory
31 changes: 28 additions & 3 deletions sale_rental/models/product.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Copyright 2014-2019 Akretion France (http://www.akretion.com)
# Copyright 2014-2021 Akretion France (http://www.akretion.com)
# @author Alexis de Lattre <[email protected]>
# Copyright 2016-2019 Sodexis (http://sodexis.com)
# Copyright 2016-2021 Sodexis (http://sodexis.com)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, fields, models, _
Expand All @@ -17,7 +17,7 @@ class ProductProduct(models.Model):
# Link rented HW product -> rental service
rental_service_ids = fields.One2many(
'product.product', 'rented_product_id',
string='Rental Services')
string='Related Rental Services')

@api.constrains('rented_product_id', 'must_have_dates', 'type', 'uom_id')
def _check_rental(self):
Expand All @@ -39,3 +39,28 @@ def _check_rental(self):
raise ValidationError(_(
"The unit of measure of the rental product '%s' must "
"be 'Day'.") % product.name)


class ProductTemplate(models.Model):
_inherit = 'product.template'

rented_product_tmpl_id = fields.Many2one(
'product.template', compute='_compute_rented_product_tmpl_id',
string='Rented Product',
inverse='_set_rented_product_tmpl_id', store=True)
rental_service_tmpl_ids = fields.One2many(
'product.template', 'rented_product_tmpl_id',
string='Rental Services')

@api.depends('product_variant_ids', 'product_variant_ids.rented_product_id')
def _compute_rented_product_tmpl_id(self):
unique_variants = self.filtered(lambda template: len(template.product_variant_ids) == 1)
for template in unique_variants:
template.rented_product_tmpl_id = template.product_variant_ids.rented_product_id.product_tmpl_id.id
for template in (self - unique_variants):
template.rented_product_tmpl_id = False

def _set_rented_product_tmpl_id(self):
for template in self:
if len(template.product_variant_ids) == 1:
template.product_variant_ids.rented_product_id = template.rented_product_tmpl_id.product_variant_ids[0].id
Loading

0 comments on commit ac64654

Please sign in to comment.