Skip to content

Commit

Permalink
Separate onchange methods for bin and mpn fields
Browse files Browse the repository at this point in the history
Refactored the `_onchange_format_fields_upper` method into two distinct methods: `_onchange_format_mpn_upper` and `_onchange_format_bin_upper`. This change filters products based on whether their `mpn` or `bin` fields are already uppercase, optimizing performance by avoiding unnecessary updates.
  • Loading branch information
cbusillo committed Oct 16, 2024
1 parent 4b753a5 commit 2b709cf
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions product_connect/models/product_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,15 @@ def name_get(self) -> list[tuple[int, str]]:
result.append((product.id, name))
return result

@api.onchange("bin", "mpn")
def _onchange_format_fields_upper(self) -> None:
for product in self:
product.mpn = product.mpn.upper() if product.mpn else False
product.bin = product.bin.upper() if product.bin else False
@api.onchange("mpn")
def _onchange_format_mpn_upper(self) -> None:
for product in self.filtered(lambda p: p.mpn and p.mpn.upper() != p.mpn):
product.mpn = product.mpn.upper()

@api.onchange("bin")
def _onchange_format_bin_upper(self) -> None:
for product in self.filtered(lambda p: p.bin and p.bin.upper() != p.bin):
product.bin = product.bin.upper()

def _products_from_existing_products(self, field_name: str, field_value: str) -> list[dict[str, str]]:
is_new_product = isinstance(self.id, models.NewId)
Expand Down

0 comments on commit 2b709cf

Please sign in to comment.