Skip to content

Commit

Permalink
sale_rental: black, isort, etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexis-via committed Dec 6, 2021
1 parent ac64654 commit 7a521f5
Show file tree
Hide file tree
Showing 18 changed files with 928 additions and 633 deletions.
40 changes: 20 additions & 20 deletions sale_rental/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
'name': 'Sale Rental',
'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': [
'security/ir.model.access.csv',
'security/sale_rental_security.xml',
'data/rental_data.xml',
'views/sale_order.xml',
'views/stock_warehouse.xml',
'views/sale_rental.xml',
'wizard/create_rental_product_view.xml',
'views/product.xml',
"name": "Sale Rental",
"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": [
"security/ir.model.access.csv",
"security/sale_rental_security.xml",
"data/rental_data.xml",
"views/sale_order.xml",
"views/stock_warehouse.xml",
"views/sale_rental.xml",
"wizard/create_rental_product_view.xml",
"views/product.xml",
],
'demo': ['demo/rental_demo.xml'],
'installable': True,
"demo": ["demo/rental_demo.xml"],
"installable": True,
}
9 changes: 4 additions & 5 deletions sale_rental/data/rental_data.xml
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8" ?>
<!--
Copyright 2014-2021 Akretion France (http://www.akretion.com/)
@author Alexis de Lattre <[email protected]>
Copyright 2016-2021 Sodexis
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"/>
<field name="warehouse_selectable" eval="True" />
<field name="product_selectable" eval="False" />
</record>

<record id="route_warehouse0_sell_rented_product" model="stock.location.route">
Expand All @@ -21,7 +20,7 @@
</record>

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

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


<odoo noupdate="1">

<record id="rent_consu_delivery_01" model="product.product">
<field name="name">Rental of one Three-Seat Sofa</field>
<field name="default_code">RENT-FURN_8999</field>
<field name="categ_id" ref="product.product_category_5"/>
<field name="sale_ok" eval="True"/>
<field name="purchase_ok" eval="False"/>
<field name="categ_id" ref="product.product_category_5" />
<field name="sale_ok" eval="True" />
<field name="purchase_ok" eval="False" />
<field name="list_price">5</field>
<field name="type">service</field>
<field name="uom_id" ref="uom.product_uom_day"/>
<field name="uom_po_id" ref="uom.product_uom_day"/>
<field name="must_have_dates" eval="True"/>
<field name="rented_product_id" ref="product.consu_delivery_01"/>
<field name="uom_id" ref="uom.product_uom_day" />
<field name="uom_po_id" ref="uom.product_uom_day" />
<field name="must_have_dates" eval="True" />
<field name="rented_product_id" ref="product.consu_delivery_01" />
<!-- The 'stock' module sets it as type = 'product'
This XMLID is misleading -->
</record>

<record id="rent_product_product_20" model="product.product">
<field name="name">Rental of one Flipover</field>
<field name="default_code">RENT-FURN_9001</field>
<field name="categ_id" ref="product.product_category_5"/>
<field name="sale_ok" eval="True"/>
<field name="purchase_ok" eval="False"/>
<field name="categ_id" ref="product.product_category_5" />
<field name="sale_ok" eval="True" />
<field name="purchase_ok" eval="False" />
<field name="list_price">4</field>
<field name="type">service</field>
<field name="uom_id" ref="uom.product_uom_day"/>
<field name="uom_po_id" ref="uom.product_uom_day"/>
<field name="must_have_dates" eval="True"/>
<field name="rented_product_id" ref="product.product_product_20"/>
<field name="uom_id" ref="uom.product_uom_day" />
<field name="uom_po_id" ref="uom.product_uom_day" />
<field name="must_have_dates" eval="True" />
<field name="rented_product_id" ref="product.product_product_20" />
</record>

<record id="rent_product_product_25" model="product.product">
<field name="name">Rental of one Acoustic Bloc Screens</field>
<field name="default_code">RENT-FURN_6666</field>
<field name="categ_id" ref="product.product_category_5"/>
<field name="sale_ok" eval="True"/>
<field name="purchase_ok" eval="False"/>
<field name="categ_id" ref="product.product_category_5" />
<field name="sale_ok" eval="True" />
<field name="purchase_ok" eval="False" />
<field name="list_price">6</field>
<field name="type">service</field>
<field name="uom_id" ref="uom.product_uom_day"/>
<field name="uom_po_id" ref="uom.product_uom_day"/>
<field name="must_have_dates" eval="True"/>
<field name="rented_product_id" ref="product.product_product_25"/>
<field name="uom_id" ref="uom.product_uom_day" />
<field name="uom_po_id" ref="uom.product_uom_day" />
<field name="must_have_dates" eval="True" />
<field name="rented_product_id" ref="product.product_product_25" />
</record>

<!-- Create inventory on Rental In for these products -->
Expand All @@ -59,7 +57,11 @@
</record>

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


Expand Down
81 changes: 50 additions & 31 deletions sale_rental/models/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,64 +3,83 @@
# 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, _
from odoo import _, api, fields, models
from odoo.exceptions import ValidationError


class ProductProduct(models.Model):
_inherit = 'product.product'
_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'))])
"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')
"product.product", "rented_product_id", string="Related Rental Services"
)

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


class ProductTemplate(models.Model):
_inherit = 'product.template'
_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)
"product.template",
compute="_compute_rented_product_tmpl_id",
string="Rented Product",
inverse="_inverse_rented_product_tmpl_id",
store=True,
)
rental_service_tmpl_ids = fields.One2many(
'product.template', 'rented_product_tmpl_id',
string='Rental Services')
"product.template", "rented_product_tmpl_id", string="Rental Services"
)

@api.depends('product_variant_ids', 'product_variant_ids.rented_product_id')
@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)
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 = (
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):
def _inverse_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
template.product_variant_ids.rented_product_id = (
template.rented_product_tmpl_id.product_variant_ids[0].id
)
Loading

0 comments on commit 7a521f5

Please sign in to comment.