mirror of
https://github.com/OCA/report-print-send.git
synced 2025-02-16 07:11:31 +02:00
[FIX] printing_auto_base: don't print twice
Fix same record printed multiple times
This commit is contained in:
committed by
Jacques-Etienne Baudoux
parent
fb24e652fe
commit
28ad399edf
@@ -94,13 +94,13 @@ class PrintingAuto(models.Model):
|
||||
domain = safe_eval(self.condition, {"env": self.env})
|
||||
return record.filtered_domain(domain)
|
||||
|
||||
def _get_content(self, record):
|
||||
def _get_content(self, records):
|
||||
generate_data_func = getattr(
|
||||
self, f"_generate_data_from_{self.data_source}", None
|
||||
)
|
||||
content = []
|
||||
if generate_data_func:
|
||||
records = self._get_record(record)
|
||||
records = self._get_record(records)
|
||||
for record in records:
|
||||
content.append(generate_data_func(record)[0])
|
||||
return content
|
||||
@@ -127,16 +127,16 @@ class PrintingAuto(models.Model):
|
||||
)
|
||||
return [data]
|
||||
|
||||
def do_print(self, record):
|
||||
def do_print(self, records):
|
||||
self.ensure_one()
|
||||
record.ensure_one()
|
||||
|
||||
behaviour = self._get_behaviour()
|
||||
printer = behaviour["printer"]
|
||||
|
||||
if self.nbr_of_copies <= 0:
|
||||
return (printer, 0)
|
||||
if not self._check_condition(record):
|
||||
records = self._check_condition(records)
|
||||
if not records:
|
||||
return (printer, 0)
|
||||
|
||||
if not printer:
|
||||
@@ -145,7 +145,7 @@ class PrintingAuto(models.Model):
|
||||
)
|
||||
|
||||
count = 0
|
||||
for content in self._get_content(record):
|
||||
for content in self._get_content(records):
|
||||
for _n in range(self.nbr_of_copies):
|
||||
printer.print_document(report=None, content=content, **behaviour)
|
||||
count += 1
|
||||
|
||||
@@ -38,7 +38,6 @@ class PrintingAutoMixin(models.AbstractModel):
|
||||
return self.auto_printing_ids
|
||||
|
||||
def _do_print_auto(self, printing_auto):
|
||||
self.ensure_one()
|
||||
printing_auto.ensure_one()
|
||||
printer, count = printing_auto.do_print(self)
|
||||
if count:
|
||||
@@ -63,6 +62,12 @@ class PrintingAutoMixin(models.AbstractModel):
|
||||
def handle_print_auto(self):
|
||||
"""Print some report or attachment directly to the corresponding printer."""
|
||||
self._on_printing_auto_start()
|
||||
to_print = {}
|
||||
for record in self:
|
||||
for printing_auto in record._get_printing_auto():
|
||||
record._handle_print_auto(printing_auto)
|
||||
if printing_auto not in to_print.keys():
|
||||
to_print[printing_auto] = record
|
||||
else:
|
||||
to_print[printing_auto] |= record
|
||||
for printing_auto, records in to_print.items():
|
||||
records._handle_print_auto(printing_auto)
|
||||
|
||||
Reference in New Issue
Block a user