Skip to content

Commit

Permalink
[FIX] Associate the related product with the product template in the …
Browse files Browse the repository at this point in the history
…Rental Price tab
  • Loading branch information
edescalona committed Jan 10, 2025
1 parent a0c291c commit 35f9c01
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions rental_pricelist/models/product_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,6 @@ class ProductTemplate(models.Model):
copy=False,
)

"""
This field defines which product.product is associated with the product.template
and obtains the data necessary for Rental.
"""
product_value_ids = fields.Many2many(
"product.product", compute="_compute_product_value_ids", store=True
)
product_related_id = fields.Many2one(
"product.product",
domain="[('id','in',product_value_ids)]",
help="Defines the product associated with the product template.",
)

month_scale_pricelist_item_ids = fields.One2many(
comodel_name="product.pricelist.item",
inverse_name="month_item_tmpl_id",
Expand All @@ -110,13 +97,29 @@ class ProductTemplate(models.Model):
copy=False,
)

"""
This field defines which product.product is associated with the product.template
and obtains the data necessary for Rental.
"""
product_value_ids = fields.Many2many(
"product.product", compute="_compute_product_value_ids", store=True
)
product_related_id = fields.Many2one(
"product.product",
domain="[('id','in',product_value_ids)]",
help="Defines the product associated with the product template.",
)

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

def _get_product_by_template(self, limit=1000):
product_tmpl_id = self._origin.id if hasattr(self, "_origin") else self.id
product_ids = self.env["product.product"].search_read(
domain=[["product_tmpl_id", "=", self.id]], fields=["id"], limit=limit
domain=[["product_tmpl_id", "=", product_tmpl_id]],
fields=["id"],
limit=limit,
)
return product_ids

Expand All @@ -139,7 +142,7 @@ def onchange_rental_of_month_day_hour(self):
if product_id:
self.product_related_id = product_id[0]["id"]

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

View check run for this annotation

Codecov / codecov/patch

rental_pricelist/models/product_template.py#L143

Added line #L143 was not covered by tests

@api.depends("product_related_id")
@api.depends("product_related_id", "rental")
def _compute_product_value_ids(self):
for product_tmpl in self:
self.product_value_ids = [
Expand Down

0 comments on commit 35f9c01

Please sign in to comment.