Skip to content

Commit

Permalink
[IMP] Add tab Rental Price in view product template
Browse files Browse the repository at this point in the history
  • Loading branch information
edescalona committed Jan 7, 2025
1 parent f732710 commit 01d83ab
Show file tree
Hide file tree
Showing 6 changed files with 481 additions and 34 deletions.
1 change: 1 addition & 0 deletions rental_pricelist/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"data": [
"views/sale_view.xml",
"views/product_view.xml",
"views/product_template_view.xml",
"views/res_company_view.xml",
],
"demo": [],
Expand Down
3 changes: 2 additions & 1 deletion rental_pricelist/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Part of rental-vertical See LICENSE file for full copyright and licensing details.
from . import sale_order_line
from . import sale_order
from . import product
from . import product_pricelist_item
from . import product
from . import product_template
from . import res_company
145 changes: 112 additions & 33 deletions rental_pricelist/models/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,67 +7,59 @@
class ProductProduct(models.Model):
_inherit = "product.product"

def _default_pricelist(self):
# TODO change default pricelist if country group exist
return self.env.ref("product.list0").id

rental_of_month = fields.Boolean(
string="Rented in months",
copy=False,
compute="_compute_rental_of_month",
inverse="_inverse_rental_of_month",
store=True,
)

rental_of_day = fields.Boolean(
string="Rented in days",
copy=False,
compute="_compute_rental_of_day", inverse="_inverse_rental_of_day", store=True
)

rental_of_hour = fields.Boolean(
string="Rented in hours",
copy=False,
compute="_compute_rental_of_hour", inverse="_inverse_rental_of_hour", store=True
)

product_rental_month_id = fields.Many2one(
comodel_name="product.product",
string="Rental Service (Month)",
ondelete="set null",
copy=False,
compute="_compute_product_rental_month_id",
inverse="_inverse_product_rental_month_id",
store=True,
)

product_rental_day_id = fields.Many2one(
comodel_name="product.product",
string="Rental Service (Day)",
ondelete="set null",
copy=False,
compute="_compute_product_rental_day_id",
inverse="_inverse_product_rental_day_id",
store=True,
)

product_rental_hour_id = fields.Many2one(
comodel_name="product.product",
string="Rental Service (Hour)",
ondelete="set null",
copy=False,
compute="_compute_product_rental_hour_id",
inverse="_inverse_product_rental_hour_id",
store=True,
)

rental_price_month = fields.Float(
string="Price / Month",
compute="_compute_rental_price_month",
inverse="_inverse_rental_price_month",
store=True,
copy=False,
readonly=False,
related="product_rental_month_id.list_price",
)

rental_price_day = fields.Float(
string="Price / Day",
compute="_compute_rental_price_day",
inverse="_inverse_rental_price_day",
store=True,
copy=False,
readonly=False,
related="product_rental_day_id.list_price",
)

rental_price_hour = fields.Float(
string="Price / Hour",
compute="_compute_rental_price_hour",
inverse="_inverse_rental_price_hour",
store=True,
copy=False,
readonly=False,
related="product_rental_hour_id.list_price",
)

Expand All @@ -92,11 +84,98 @@ def _default_pricelist(self):
copy=False,
)

def_pricelist_id = fields.Many2one(
comodel_name="product.pricelist",
string="Default Pricelist",
default=lambda self: self._default_pricelist(),
)
@api.depends("product_tmpl_id.rental_of_month")
def _compute_rental_of_month(self):
for product in self:
product.rental_of_month = product.product_tmpl_id.rental_of_month

def _inverse_rental_of_month(self):
for product in self:
product.product_tmpl_id.rental_of_month = product.rental_of_month

@api.depends("product_tmpl_id.product_rental_month_id")
def _compute_product_rental_month_id(self):
for product in self:
product.product_rental_month_id = (
product.product_tmpl_id.product_rental_month_id
)

def _inverse_product_rental_month_id(self):
for product in self:
product.product_tmpl_id.product_rental_month_id = (
product.product_rental_month_id
)

@api.depends("product_tmpl_id.rental_price_month")
def _compute_rental_price_month(self):
for product in self:
product.rental_price_month = product.product_tmpl_id.rental_price_month

Check warning on line 112 in rental_pricelist/models/product.py

View check run for this annotation

Codecov / codecov/patch

rental_pricelist/models/product.py#L112

Added line #L112 was not covered by tests

def _inverse_rental_price_month(self):
for product in self:
product.product_tmpl_id.rental_price_month = product.rental_price_month

Check warning on line 116 in rental_pricelist/models/product.py

View check run for this annotation

Codecov / codecov/patch

rental_pricelist/models/product.py#L116

Added line #L116 was not covered by tests

@api.depends("product_tmpl_id.rental_of_day")
def _compute_rental_of_day(self):
for product in self:
product.rental_of_day = product.product_tmpl_id.rental_of_day

def _inverse_rental_of_day(self):
for product in self:
product.product_tmpl_id.rental_of_day = product.rental_of_day

@api.depends("product_tmpl_id.product_rental_day_id")
def _compute_product_rental_day_id(self):
for product in self:
product.product_rental_day_id = (
product.product_tmpl_id.product_rental_day_id
)

def _inverse_product_rental_day_id(self):
for product in self:
product.product_tmpl_id.product_rental_day_id = (
product.product_rental_day_id
)

@api.depends("product_tmpl_id.rental_price_day")
def _compute_rental_price_day(self):
for product in self:
product.rental_price_day = product.product_tmpl_id.rental_price_day

Check warning on line 143 in rental_pricelist/models/product.py

View check run for this annotation

Codecov / codecov/patch

rental_pricelist/models/product.py#L143

Added line #L143 was not covered by tests

def _inverse_rental_price_day(self):
for product in self:
product.product_tmpl_id.rental_price_day = product.rental_price_day

Check warning on line 147 in rental_pricelist/models/product.py

View check run for this annotation

Codecov / codecov/patch

rental_pricelist/models/product.py#L147

Added line #L147 was not covered by tests

@api.depends("product_tmpl_id.rental_of_hour")
def _compute_rental_of_hour(self):
for product in self:
product.rental_of_hour = product.product_tmpl_id.rental_of_hour

def _inverse_rental_of_hour(self):
for product in self:
product.product_tmpl_id.rental_of_hour = product.rental_of_hour

@api.depends("product_tmpl_id.rental_price_hour")
def _compute_rental_price_hour(self):
for product in self:
product.rental_price_hour = product.product_tmpl_id.rental_price_hour

Check warning on line 161 in rental_pricelist/models/product.py

View check run for this annotation

Codecov / codecov/patch

rental_pricelist/models/product.py#L161

Added line #L161 was not covered by tests

def _inverse_rental_price_hour(self):
for product in self:
product.product_tmpl_id.rental_price_hour = product.rental_price_hour

Check warning on line 165 in rental_pricelist/models/product.py

View check run for this annotation

Codecov / codecov/patch

rental_pricelist/models/product.py#L165

Added line #L165 was not covered by tests

@api.depends("product_tmpl_id.product_rental_hour_id")
def _compute_product_rental_hour_id(self):
for product in self:
product.product_rental_hour_id = (
product.product_tmpl_id.product_rental_hour_id
)

def _inverse_product_rental_hour_id(self):
for product in self:
product.product_tmpl_id.product_rental_hour_id = (
product.product_rental_hour_id
)

# override from sale_rental, to remove Uom constrain
@api.constrains("rented_product_id", "must_have_dates", "type", "uom_id")
Expand Down
15 changes: 15 additions & 0 deletions rental_pricelist/models/product_pricelist_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,31 @@ class ProductPricelistItem(models.Model):
string="Rental Service (Day)",
)

day_item_tmpl_id = fields.Many2one(
comodel_name="product.template",
string="Rental Service (Day)",
)

month_item_id = fields.Many2one(
comodel_name="product.product",
string="Rental Service (Month)",
)

month_item_tmpl_id = fields.Many2one(
comodel_name="product.template",
string="Rental Service (Month)",
)

hour_item_id = fields.Many2one(
comodel_name="product.product",
string="Rental Service (Hour)",
)

hour_item_tmpl_id = fields.Many2one(
comodel_name="product.product",
string="Rental Service (Hour)",
)

@api.onchange("product_id")
def _onchange_product_id(self):
uom_month = self.env.ref("rental_base.product_uom_month")
Expand Down
Loading

0 comments on commit 01d83ab

Please sign in to comment.