Skip to content

Commit

Permalink
Port sale_start_end_dates and sale_rental (OCA#353)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexis de Lattre authored and SimoRubi committed Jan 19, 2018
1 parent 25ca2e6 commit 96ce34c
Show file tree
Hide file tree
Showing 30 changed files with 1,117 additions and 1,231 deletions.
29 changes: 24 additions & 5 deletions sale_rental/README.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3

===========
Sale Rental
===========

Expand Down Expand Up @@ -47,7 +52,11 @@ a stock move from *Rental Out* to *Customers*.

Please refer to `this screencast <https://www.youtube.com/watch?v=9o0QrGryBn8>`
to get a demo of the installation, configuration and use of this module
(note that this screencast is for Odoo v7, not v8).
(note that this screencast is for Odoo v7).

.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/167/9.0

Known issues / Roadmap
======================
Expand All @@ -57,6 +66,14 @@ This module has the following limitations:
* No support for planning/agenda of the rented products
* the unit of measure of the rental services must be *Day* (the rental per hours / 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.

Credits
=======

Expand All @@ -68,12 +85,14 @@ Contributors
Maintainer
----------

.. image:: http://odoo-community.org/logo.png
.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: http://odoo-community.org
:target: https://odoo-community.org

This module is maintained by the OCA.

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.
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.

To contribute to this module, please visit http://odoo-community.org.
To contribute to this module, please visit https://odoo-community.org.
24 changes: 2 additions & 22 deletions sale_rental/__init__.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,4 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# Sale Rental module for Odoo
# Copyright (C) 2014-2015 Akretion (http://www.akretion.com)
# @author Alexis de Lattre <alexis.delattre@akretion.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
# -*- coding: utf-8 -*-

from . import rental
from . import models
from . import wizard
47 changes: 15 additions & 32 deletions sale_rental/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,44 +1,27 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# Rental module for Odoo
# Copyright (C) 2014-2015 Akretion (http://www.akretion.com)
# @author Alexis de Lattre <alexis.delattre@akretion.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

# -*- coding: utf-8 -*-
# © 2014-2016 Akretion (http://www.akretion.com)
# @author Alexis de Lattre <alexis.delattre@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
'name': 'Rental',
'version': '8.0.0.1.0',
'version': '9.0.1.0.0',
'category': 'Sales Management',
'license': 'AGPL-3',
'summary': 'Manage Rental of Products',
'author': 'Akretion',
'author': 'Akretion, Odoo Community Association (OCA)',
'website': 'http://www.akretion.com',
'depends': ['sale_start_end_dates', 'stock'],
'depends': ['sale_start_end_dates', 'sale_stock'],
'data': [
'sale_view.xml',
'stock_view.xml',
'rental_view.xml',
'rental_data.xml',
'data/rental_data.xml',
'views/sale_order.xml',
'views/stock.xml',
'views/sale_rental.xml',
'wizard/create_rental_product_view.xml',
'product_view.xml',
'views/product.xml',
'security/ir.model.access.csv',
'security/sale_rental_security.xml',
],
'demo': ['rental_demo.xml'],
'installable': False,
'demo': ['demo/rental_demo.xml'],
'installable': True,
}
26 changes: 26 additions & 0 deletions sale_rental/data/rental_data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
© 2014-2016 Akretion (http://www.akretion.com/)
@author Alexis de Lattre <alexis.delattre@akretion.com>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->

<odoo noupdate="1">

<record id="route_warehouse0_rental" model="stock.location.route">
<field name="name">Rent</field>
<field name="sequence">100</field>
<field name="warehouse_selectable" eval="True"/>
<field name="product_selectable" eval="False"/>
</record>

<record id="route_warehouse0_sell_rented_product" model="stock.location.route">
<field name="name">Sell Rented Product</field>
<field name="sequence">100</field>
</record>

<record id="stock.warehouse0" model="stock.warehouse">
<field name="rental_allowed" eval="True"/>
</record>

</odoo>
43 changes: 10 additions & 33 deletions sale_rental/rental_demo.xml → sale_rental/demo/rental_demo.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>

<!--
Copyright (C) 2014-2015 Akretion (http://www.akretion.com/)
@author Alexis de Lattre <alexis.delattre@akretion.com>
The licence is in the file __openerp__.py
© 2014-2016 Akretion (http://www.akretion.com/)
@author Alexis de Lattre <alexis.delattre@akretion.com>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->


<openerp>
<data noupdate="1">
<odoo noupdate="1">

<record id="rent_product_product_6" model="product.product">
<field name="name">Rental of one iPad Mini</field>
Expand Down Expand Up @@ -54,33 +52,12 @@
<field name="name">Inventory for rented products</field>
</record>

<record id="rental_inventory_line_1" model="stock.inventory.line">
<field name="product_id" ref="product.product_product_6"/>
<field name="product_uom_id" ref="product.product_uom_unit"/>
<field name="inventory_id" ref="rental_inventory"/>
<field name="product_qty">56.0</field>
<field name="location_id" ref="rental_in_stock_location"/>
</record>

<record id="rental_inventory_line_2" model="stock.inventory.line">
<field name="product_id" ref="product.product_product_8"/>
<field name="product_uom_id" ref="product.product_uom_unit"/>
<field name="inventory_id" ref="rental_inventory"/>
<field name="product_qty">46.0</field>
<field name="location_id" ref="rental_in_stock_location"/>
</record>

<record id="rental_inventory_line_3" model="stock.inventory.line">
<field name="product_id" ref="product.product_product_25"/>
<field name="product_uom_id" ref="product.product_uom_unit"/>
<field name="inventory_id" ref="rental_inventory"/>
<field name="product_qty">2.0</field>
<field name="location_id" ref="rental_in_stock_location"/>
</record>

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

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

</odoo>
6 changes: 6 additions & 0 deletions sale_rental/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-

from . import product
from . import sale_order
from . import sale_rental
from . import stock
51 changes: 51 additions & 0 deletions sale_rental/models/product.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# -*- coding: utf-8 -*-
# © 2014-2016 Akretion (http://www.akretion.com)
# @author Alexis de Lattre <alexis.delattre@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from openerp import models, fields, api, _
from openerp.exceptions import ValidationError


class ProductProduct(models.Model):
_inherit = 'product.product'

# Link rental service -> rented HW product
rented_product_id = fields.Many2one(
'product.product', string='Related Rented Product',
domain=[('type', 'in', ('product', 'consu'))])
# Link rented HW product -> rental service
rental_service_ids = fields.One2many(
'product.product', 'rented_product_id',
string='Related Rental Services')

@api.one
@api.constrains('rented_product_id', 'must_have_dates', 'type', 'uom_id')
def _check_rental(self):
if self.rented_product_id and self.type != 'service':
raise ValidationError(_(
"The rental product '%s' must be of type 'Service'.")
% self.name)
if self.rented_product_id and not self.must_have_dates:
raise ValidationError(_(
"The rental product '%s' must have the option "
"'Must Have Start and End Dates' checked.")
% self.name)
# In the future, we would like to support all time UoMs
# but it is more complex and requires additionnal developments
day_uom = self.env.ref('product.product_uom_day')
if self.rented_product_id and self.uom_id != day_uom:
raise ValidationError(_(
"The unit of measure of the rental product '%s' must "
"be 'Day'.") % self.name)

@api.multi
def _need_procurement(self):
# Missing self.ensure_one() in the native code !
res = super(ProductProduct, self)._need_procurement()
if not res:
for product in self:
if product.type == 'service' and product.rented_product_id:
return True
# TODO find a replacement for soline.rental_type == 'new_rental')
return res
Loading

0 comments on commit 96ce34c

Please sign in to comment.