Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][FIX] printing_simple_configuration: add company_id to printer #376

Merged
merged 1 commit into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions printing_simple_configuration/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
"category": "Generic Modules/Base",
"website": "https://github.com/OCA/report-print-send",
"author": "Akretion,Odoo Community Association (OCA)",
"maintainer": [
"maintainers": [
"bealdav",
],
"maturity": "Alpha",
"license": "AGPL-3",
"depends": [
"stock",
"sale_stock",
],
"data": [
"views/company.xml",
Expand Down
38 changes: 37 additions & 1 deletion printing_simple_configuration/models/printer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
from odoo import fields, models
import logging

from odoo import _, api, fields, models
from odoo.exceptions import UserError

_logger = logging.getLogger(__name__)


class Printer(models.Model):
Expand All @@ -19,3 +24,34 @@
"In some case, erp project may be imply minimal config as module data\n"
"with some fields might updated within the interface"
)
company_id = fields.Many2one(
"res.company",
related="config_id.company_id",
store=True,
)

@api.model
def _get_printer_by_usage(self):
printers = {}
company = self.env.company

Check warning on line 36 in printing_simple_configuration/models/printer.py

View check run for this annotation

Codecov / codecov/patch

printing_simple_configuration/models/printer.py#L35-L36

Added lines #L35 - L36 were not covered by tests

domain = [("company_id", "=", company.id)]

Check warning on line 38 in printing_simple_configuration/models/printer.py

View check run for this annotation

Codecov / codecov/patch

printing_simple_configuration/models/printer.py#L38

Added line #L38 was not covered by tests
if self.env.user.property_warehouse_id:
domain.append(("warehouse_id", "=", self.env.user.property_warehouse_id.id))

Check warning on line 40 in printing_simple_configuration/models/printer.py

View check run for this annotation

Codecov / codecov/patch

printing_simple_configuration/models/printer.py#L40

Added line #L40 was not covered by tests
else:
domain.append(("warehouse_id", "=", False))

Check warning on line 42 in printing_simple_configuration/models/printer.py

View check run for this annotation

Codecov / codecov/patch

printing_simple_configuration/models/printer.py#L42

Added line #L42 was not covered by tests

for device in self.search(domain, order="warehouse_id DESC, usage, name DESC"):
conf = device.sudo().config_id
printers[device.usage] = {

Check warning on line 46 in printing_simple_configuration/models/printer.py

View check run for this annotation

Codecov / codecov/patch

printing_simple_configuration/models/printer.py#L45-L46

Added lines #L45 - L46 were not covered by tests
"location": "https://%s:%s" % (conf.server, conf.port or 0),
"name": device.name,
"comment": device.comment,
}
_logger.info(" >>> Printers %s" % printers)

Check warning on line 51 in printing_simple_configuration/models/printer.py

View check run for this annotation

Codecov / codecov/patch

printing_simple_configuration/models/printer.py#L51

Added line #L51 was not covered by tests
if not printers:
raise UserError(

Check warning on line 53 in printing_simple_configuration/models/printer.py

View check run for this annotation

Codecov / codecov/patch

printing_simple_configuration/models/printer.py#L53

Added line #L53 was not covered by tests
_("There is no printer accessible to you in the company %s")
% company.name
)
return printers

Check warning on line 57 in printing_simple_configuration/models/printer.py

View check run for this annotation

Codecov / codecov/patch

printing_simple_configuration/models/printer.py#L57

Added line #L57 was not covered by tests
Loading