Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions base_sequence_option/models/ir_sequence_option.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,21 +96,23 @@ class IrSequenceOptionLine(models.Model):
store=True,
)

def get_model_options(self, model):
return self.sudo().search(
[("use_sequence_option", "=", True), ("model", "=", model)]
)
def get_model_options(self, model, company=False):
domain = [("use_sequence_option", "=", True), ("model", "=", model)]
# Filter the company in SQL, options of all companies can be many
if company:
domain.append(("company_id", "=", company.id))
return self.sudo().search(domain)

def get_sequence(self, record, options=False):
"""
Find sequence option that match the record values
"""
if not options:
options = self.get_model_options(record._name)
# multi-company
company = (
hasattr(record, "company_id") and record.company_id or self.env.company
)
if not options:
options = self.get_model_options(record._name, company=company)
options = options.filtered(lambda l: l.company_id == company)
sequence = self.env["ir.sequence"]
for option in options:
Expand Down
Loading