mirror of
https://gitlab.com/hibou-io/hibou-odoo/suite.git
synced 2025-01-20 12:37:31 +02:00
[FIX] sale_planner: allow filtered collections to be Falsey
This commit is contained in:
@@ -22,23 +22,29 @@ from ..models.res_config_settings import sale_planner_warehouse_ids, sale_planne
|
|||||||
|
|
||||||
class FakeCollection():
|
class FakeCollection():
|
||||||
def __init__(self, vals):
|
def __init__(self, vals):
|
||||||
self.vals = vals
|
self._vals = vals
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
for v in self.vals:
|
for v in self._vals:
|
||||||
yield v
|
yield v
|
||||||
|
|
||||||
def filtered(self, f):
|
def filtered(self, f):
|
||||||
return self.__class__([v for v in self.vals if f(v)])
|
return self.__class__([v for v in self._vals if f(v)])
|
||||||
# return filter(f, self.vals)
|
# return filter(f, self.vals)
|
||||||
|
|
||||||
def mapped(self, s):
|
def mapped(self, s):
|
||||||
# note this only maps to one level and doesn't really support recordset
|
# note this only maps to one level and doesn't really support recordset
|
||||||
return [v[s] for v in self.vals]
|
return [v[s] for v in self._vals]
|
||||||
|
|
||||||
def sudo(self, *args, **kwargs):
|
def sudo(self, *args, **kwargs):
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
def __bool__(self):
|
||||||
|
# FakeCollection can be empty, all subclasses cannot (currently)
|
||||||
|
if self.__class__ != FakeCollection:
|
||||||
|
return True
|
||||||
|
return bool(self._vals)
|
||||||
|
|
||||||
|
|
||||||
class FakePartner(FakeCollection):
|
class FakePartner(FakeCollection):
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
|
|||||||
Reference in New Issue
Block a user