Skip to content

Commit

Permalink
product_main_supplierinfo: replace '_get_sellers' by std '_get_filter…
Browse files Browse the repository at this point in the history
…ed_sellers'
  • Loading branch information
sebalix committed Dec 10, 2024
1 parent aa7eed0 commit c0e47f7
Showing 1 changed file with 3 additions and 26 deletions.
29 changes: 3 additions & 26 deletions product_main_supplierinfo/models/product_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,8 @@ class ProductProduct(models.Model):
)
@api.depends_context("company")
def _compute_main_seller_id(self):
for product in self:
sellers = product._get_sellers()
product.main_seller_id = fields.first(sellers)

def _get_sellers(self):
"""Returns all available sellers of a product based on some constraints.
They are ordered and filtered like it is done in the standard 'product' addon.
"""
self.ensure_one()
all_sellers = self._prepare_sellers(False).filtered(
lambda s: not s.company_id or s.company_id.id == self.env.company.id
)
today = fields.Date.context_today(self)
sellers = all_sellers.filtered(
lambda s: (
(s.product_id == self or not s.product_id)
and (
(s.date_start <= today if s.date_start else True)
and (s.date_end >= today if s.date_end else True)
)
for product in self:
product.main_seller_id = fields.first(
product._get_filtered_sellers(quantity=None, date=today).sorted("price")
)
)
if not sellers:
sellers = all_sellers.filtered(lambda s: (s.product_id == self))
if not sellers:
sellers = all_sellers.filtered(lambda s: not s.product_id)
return sellers.sorted("price")

0 comments on commit c0e47f7

Please sign in to comment.