Skip to content

Commit

Permalink
[IMP] Set product related with product template create
Browse files Browse the repository at this point in the history
  • Loading branch information
edescalona committed Jan 9, 2025
1 parent 01d83ab commit a0c291c
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions rental_pricelist/models/product_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,24 @@ def _get_product_by_template(self, limit=1000):
)
return product_ids

def write(self, vals):
if vals.get("rental", False):
@api.model_create_multi
def create(self, vals_list):
product_tmpl_ids = super().create(vals_list)
for product_tmpl_id in product_tmpl_ids:
if product_tmpl_id.rental:
product_id = product_tmpl_id._get_product_by_template(limit=1)

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

View check run for this annotation

Codecov / codecov/patch

rental_pricelist/models/product_template.py#L128

Added line #L128 was not covered by tests
if product_id:
product_tmpl_id.product_related_id = product_id[0]["id"]

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

View check run for this annotation

Codecov / codecov/patch

rental_pricelist/models/product_template.py#L130

Added line #L130 was not covered by tests
return product_tmpl_ids

@api.onchange("rental_of_month", "rental_of_day", "rental_of_hour")
def onchange_rental_of_month_day_hour(self):
if (
self.rental_of_month or self.rental_of_day or self.rental_of_hour
) and not self.product_related_id:
product_id = self._get_product_by_template(limit=1)

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

View check run for this annotation

Codecov / codecov/patch

rental_pricelist/models/product_template.py#L138

Added line #L138 was not covered by tests
if product_id:
vals["product_related_id"] = product_id[0]["id"]
return super().write(vals)
self.product_related_id = product_id[0]["id"]

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

View check run for this annotation

Codecov / codecov/patch

rental_pricelist/models/product_template.py#L140

Added line #L140 was not covered by tests

@api.depends("product_related_id")
def _compute_product_value_ids(self):
Expand Down

0 comments on commit a0c291c

Please sign in to comment.