From 350e30f263b8f18bcb4269b12774f56c91001934 Mon Sep 17 00:00:00 2001 From: Camila Vives Date: Thu, 23 Jan 2025 10:03:00 -0300 Subject: [PATCH 1/6] Update from template --- .copier-answers.yml | 10 ++ .github/workflows/pre-commit.yml | 34 +++++++ .gitignore | 12 ++- .pre-commit-config.yaml | 69 ++++++++++++++ README.md | 11 +-- pyproject.toml | 152 +++++++++++++++++++++++++++++++ 6 files changed, 278 insertions(+), 10 deletions(-) create mode 100644 .copier-answers.yml create mode 100644 .github/workflows/pre-commit.yml create mode 100644 .pre-commit-config.yaml create mode 100644 pyproject.toml diff --git a/.copier-answers.yml b/.copier-answers.yml new file mode 100644 index 00000000..3103e551 --- /dev/null +++ b/.copier-answers.yml @@ -0,0 +1,10 @@ +# Do NOT update manually; changes here will be overwritten by Copier +_commit: 719579f +_src_path: https://github.com/ingadhoc/addons-repo-template.git +description: ADHOC Odoo multi-company Modules +is_private: false +name: ADHOC multi-company +odoo_version: 18.0 +pre_commit_ignore: [] +slug: '' + diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml new file mode 100644 index 00000000..0915d8c3 --- /dev/null +++ b/.github/workflows/pre-commit.yml @@ -0,0 +1,34 @@ +# ⚠️ DO NOT EDIT THIS FILE, IT IS GENERATED BY COPIER ⚠️ +# Changes here will be lost on a future update. +# See: https://github.com/ingadhoc/addons-repo-template + +name: pre-commit + +on: + push: + branches: "*.0" + pull_request: + +jobs: + pre-commit: + runs-on: ubuntu-latest + steps: + - + name: Checkout + uses: actions/checkout@v4 + - + id: setup-python + name: Setup Python + uses: actions/setup-python@v5 + with: + python-version: "3.10" + cache: "pip" + - + name: Pre-commit cache + uses: actions/cache@v4 + with: + path: ~/.cache/pre-commit + key: pre-commit|${{ steps.setup-python.outputs.python-version }}|${{ hashFiles('.pre-commit-config.yaml') }} + - + name: Pre-commit + uses: pre-commit/action@v3.0.1 diff --git a/.gitignore b/.gitignore index 102f889f..a6d076d8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ +# ⚠️ DO NOT EDIT THIS FILE, IT IS GENERATED BY COPIER ⚠️ +# Changes here will be lost on a future update. +# See: https://github.com/ingadhoc/addons-repo-template + # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] @@ -37,6 +41,12 @@ coverage.xml # Translations *.mo +# Ensure we never commit pgdumps +*.dump +*.sql +*.pg +*.pg.gpg + # Mr Developer .mr.developer.cfg .project @@ -50,5 +60,3 @@ coverage.xml # Sphinx documentation docs/_build/ -# -.idea/ diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..5c1bd68b --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,69 @@ +# ⚠️ DO NOT EDIT THIS FILE, IT IS GENERATED BY COPIER ⚠️ +# Changes here will be lost on a future update. +# See: https://github.com/ingadhoc/addons-repo-template + +exclude: | + (?x) + + # We don't want to mess with tool-generated files + .svg$|/tests/([^/]+/)?cassettes/|^.copier-answers.yml$|^.github/|^eslint.config.cjs|^prettier.config.cjs| + # Library files can have extraneous formatting (even minimized) + /static/(src/)?lib/| + # Ignore build and dist directories in addons + /build/|/dist/| + # Ignore test files in addons + /tests/samples/.*| + # You don't usually want a bot to modify your legal texts + (LICENSE.*|COPYING.*) + +# Keep in sync with .github/workflows/pre-commit.yml +default_language_version: + python: python3 + +repos: + + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v5.0.0 + hooks: + - id: check-added-large-files + - id: check-case-conflict + - id: check-docstring-first + - id: check-executables-have-shebangs + - id: check-merge-conflict + - id: check-symlinks + - id: check-xml + - id: check-yaml + - id: debug-statements + - id: end-of-file-fixer + - id: mixed-line-ending + args: ["--fix=lf"] + - id: trailing-whitespace + # exclude autogenerated files + exclude: \.pot?$ + + - repo: https://github.com/OCA/odoo-pre-commit-hooks + rev: v0.0.35 + hooks: + - id: oca-checks-odoo-module + args: + - --disable=xml-dangerous-qweb-replace-low-priority,xml-view-dangerous-replace-low-priority,xml-oe-structure-missing-id + - id: oca-checks-po + args: + - --disable=po-pretty-format + + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.6.8 + hooks: + - id: ruff + args: [--fix, --exit-non-zero-on-fix] + - id: ruff-format + + - repo: https://github.com/OCA/pylint-odoo + rev: v9.1.3 + hooks: + - id: pylint_odoo + + - repo: https://github.com/rstcheck/rstcheck + rev: v6.2.1 + hooks: + - id: rstcheck diff --git a/README.md b/README.md index 83c13b01..e5e51de0 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,12 @@ -[![Code Climate](https://codeclimate.com/github/ingadhoc/multi-company/badges/gpa.svg)](https://codeclimate.com/github/ingadhoc/multi-company) +[![Coverage Status](https://coveralls.io/repos/ingadhoc//badge.png?branch=18.0)](https://coveralls.io/r/ingadhoc/?branch=18.0) +[![Code Climate](https://codeclimate.com/github/ingadhoc//badges/gpa.svg)](https://codeclimate.com/github/ingadhoc/) # ADHOC multi-company ADHOC Odoo multi-company Modules -[//]: # (addons) -[//]: # (end addons) - -Translation Status ------------------- -[![Transifex Status](https://www.transifex.com/projects/p/ingadhoc-multi-company-15-0/chart/image_png)](https://www.transifex.com/projects/p/ingadhoc-multi-company-15-0) - ---- ADHOC **Adhoc SA** - www.adhoc.com.ar +. diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..9f837a8c --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,152 @@ +[tool.ruff] +line-length = 120 + +[tool.ruff.lint] +select = [ + "E", # pycodestyle errors + "W", # pycodestyle warnings + "C90", # mccabe + "F", # pyflakes + "UP", # pyupgrade + "I", # isort +] +ignore = [ + "UP008", # pyupgrade: Use `super()` instead of `super(__class__, self)` (no autofix) + "UP031", # pyupgrade: use format specifiers instead of percent format (no autofix) + "E712", # avoid equality comparisons to False (no autofix) + "E721", # do not compare types, use 'isinstance()' (no autofix) + "E722", # do not use bare `except` (no autofix) + "E731", # do not assign `lambda` expression, use a `def` (no autofix) + "E741", # ambiguos variable name (no autofix) +] + +[tool.ruff.lint.per-file-ignores] +"__init__.py" = ["F401", "I001"] +"__manifest__.py" = ["B018"] + +[tool.ruff.lint.pycodestyle] +# line-length is set in [tool.ruff], and it's used by the formatter +# in case the formatted can't autofix the line length, it will be reported as an error +# only if it exceeds the max-line-length set here. We use 999 to effectively disable +# this check. +max-line-length = 999 + +[tool.ruff.lint.isort] +combine-as-imports = true +force-wrap-aliases = true +known-third-party = [ + "dateutil", + "git", + "gnupg", + "openupgradelib", + "pkg_resources", + "psycopg2", + "requests", + "setuptools", + "urllib2", + "yaml", +] + +[tool.ruff.lint.mccabe] +max-complexity = 20 + +[tool.pylint.master] +load-plugins = ["pylint_odoo"] +score = false + +[tool.pylint.odoolint] +manifest-required-authors = "ADHOC SA" +manifest-required-keys = ["license"] +manifest-deprecated-keys = ["description", "active"] +license-allowed = [ + "AGPL-3", + "GPL-2", + "GPL-2 or any later version", + "GPL-3", + "GPL-3 or any later version", + "LGPL-3", +] + +[tool.pylint."messages control"] +disable = "all" +enable = [ + "anomalous-backslash-in-string", + "api-one-deprecated", + "api-one-multi-together", + "assignment-from-none", + "attribute-deprecated", + "attribute-string-redundant", + "character-not-valid-in-resource-link", + "class-camelcase", + "consider-merging-classes-inherited", + "context-overridden", + "create-user-wo-reset-password", + "dangerous-default-value", + "dangerous-filter-wo-user", + "dangerous-qweb-replace-wo-priority", + "dangerous-view-replace-wo-priority", + "deprecated-data-xml-node", + "deprecated-openerp-xml-node", + "development-status-allowed", + "duplicate-id-csv", + "duplicate-key", + "duplicate-po-message-definition", + "duplicate-xml-fields", + "duplicate-xml-record-id", + "eval-referenced", + "eval-used", + # "except-pass", # Annoying + "external-request-timeout", + "file-not-used", + "incoherent-interpreter-exec-perm", + "invalid-commit", + "license-allowed", + "manifest-author-string", + "manifest-deprecated-key", + "manifest-maintainers-list", + "manifest-required-author", + "manifest-required-key", + # "manifest-version-format", # Errors on non-migrated modules, and redundant with runbot + "method-compute", + "method-inverse", + "method-required-super", + "method-search", + "missing-newline-extrafiles", + # "missing-return", # Annoying. Not applicable for computed field methods + "odoo-addons-relative-import", + "old-api7-method-defined", + "openerp-exception-warning", + "po-msgstr-variables", + "po-syntax-error", + "pointless-statement", + "pointless-string-statement", + "print-used", + "redundant-keyword-arg", + "redundant-modulename-xml", + "reimported", + "relative-import", + "renamed-field-parameter", + "resource-not-exist", + "return-in-init", + "rst-syntax-error", + "sql-injection", + "str-format-used", + "test-folder-imported", + "too-few-format-args", + "translation-contains-variable", + "translation-field", + # "translation-positional-used", # Annoying in our use case + # "translation-required", # We don't always translate everything, and that's fine + "unnecessary-utf8-coding-comment", + "unreachable", + "use-vim-comment", + "wrong-tabs-instead-of-spaces", + "xml-attribute-translatable", + "xml-deprecated-qweb-directive", + "xml-deprecated-tree-attribute", + "xml-syntax-error" +] + +[tool.pylint.reports] +output-format = "colorized" +msg-template = "{path}:{line}: [{msg_id}({symbol}), {obj}] {msg}" From b848f286dcadf4aab99e067959d37fd594ef5e31 Mon Sep 17 00:00:00 2001 From: Camila Vives Date: Thu, 23 Jan 2025 10:06:20 -0300 Subject: [PATCH 2/6] [IMP] account_multicompany_ux: remove unused variable --- .../tests/test_account_multicompany_ux_unit_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/account_multicompany_ux/tests/test_account_multicompany_ux_unit_test.py b/account_multicompany_ux/tests/test_account_multicompany_ux_unit_test.py index 74f04435..d0eec249 100644 --- a/account_multicompany_ux/tests/test_account_multicompany_ux_unit_test.py +++ b/account_multicompany_ux/tests/test_account_multicompany_ux_unit_test.py @@ -26,7 +26,7 @@ def setUp(self): 'company_ids': [self.second_company.id], }) - a_receivable = self.env['account.account'].create({ + self.env['account.account'].create({ 'code': 'X2021', 'name': 'Product Sales Receivable - (test)', 'account_type': 'asset_receivable', From 50e854a8571c79937cad0f6cd13418ca6d9291fb Mon Sep 17 00:00:00 2001 From: Camila Vives Date: Thu, 23 Jan 2025 10:12:05 -0300 Subject: [PATCH 3/6] [IMP] account_multicompany_ux: avoid sql injection risk --- .../models/res_company_property.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/account_multicompany_ux/models/res_company_property.py b/account_multicompany_ux/models/res_company_property.py index 032c1682..d7e22ee8 100644 --- a/account_multicompany_ux/models/res_company_property.py +++ b/account_multicompany_ux/models/res_company_property.py @@ -2,7 +2,11 @@ # For copyright and license notices, see __manifest__.py file in module root # directory ############################################################################## -from odoo import api, fields, models, _ +import logging +from ast import literal_eval +from psycopg2 import sql + +from odoo import _, api, fields, models, tools from odoo.exceptions import UserError from odoo import tools from lxml import etree @@ -44,8 +48,13 @@ def init(self): FROM res_company c """ - cr.execute("""CREATE or REPLACE VIEW %s as (%s - )""" % (self._table, query)) + + cr.execute( + sql.SQL("CREATE OR REPLACE VIEW {} AS ({})").format( + sql.Identifier(self._table), + sql.SQL(query) + ) + ) property_field = fields.Char( compute='_compute_property_field', From 2bb81f699f83e38d9579e5536b9633e4fe2a9b0d Mon Sep 17 00:00:00 2001 From: Camila Vives Date: Thu, 23 Jan 2025 10:13:00 -0300 Subject: [PATCH 4/6] [IMP] account_multicompany_ux: translation contains variable --- account_multicompany_ux/models/res_company_property.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/account_multicompany_ux/models/res_company_property.py b/account_multicompany_ux/models/res_company_property.py index d7e22ee8..e44a6cab 100644 --- a/account_multicompany_ux/models/res_company_property.py +++ b/account_multicompany_ux/models/res_company_property.py @@ -161,7 +161,7 @@ def _get_company_property_field(self): company_property_field = 'standard_price' else: raise UserError( - _('Property for model %s not implemented yet' % comodel)) + _('Property for model %s not implemented yet', comodel)) return company_property_field @api.depends('company_id', 'property_field') From 5c1741ee8f0744981c5dbcc8546b52ca913b45c1 Mon Sep 17 00:00:00 2001 From: Camila Vives Date: Thu, 23 Jan 2025 10:14:29 -0300 Subject: [PATCH 5/6] [IMP] website_multicompany: avoid context override --- website_multicompany/models/ir_http.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website_multicompany/models/ir_http.py b/website_multicompany/models/ir_http.py index abb2f48c..4680c80d 100644 --- a/website_multicompany/models/ir_http.py +++ b/website_multicompany/models/ir_http.py @@ -24,4 +24,4 @@ def _frontend_pre_dispatch(cls): request.update_context( allowed_company_ids=users_company_ids, ) - request.website = website.with_context(request.context) + request.website = website.with_context(**request.context) From 6186faf1c7d37bc2100f8a429ee43b7c40f56260 Mon Sep 17 00:00:00 2001 From: Camila Vives Date: Mon, 27 Jan 2025 15:32:43 -0300 Subject: [PATCH 6/6] [IMP] *: pre-commit automatic fixes --- .pre-commit-config.yaml | 2 +- account_multicompany_ux/__manifest__.py | 46 ++--- .../i18n/account_mutlicompany_usability.pot | 1 - .../models/account_account.py | 11 +- .../models/account_journal.py | 7 +- .../models/account_move.py | 9 +- .../models/account_report.py | 29 ++- .../models/product_category.py | 29 +-- .../models/product_product.py | 34 ++- .../models/product_template.py | 36 ++-- account_multicompany_ux/models/res_company.py | 26 ++- .../models/res_company_property.py | 195 ++++++++---------- .../models/res_company_property_mixin.py | 45 ++-- account_multicompany_ux/models/res_partner.py | 73 +++---- .../test_account_multicompany_ux_unit_test.py | 147 +++++++------ .../views/res_company_property_views.xml | 4 +- .../wizards/account_change_company.py | 91 +++++--- payment_multic_ux/__manifest__.py | 22 +- payment_multic_ux/models/__init__.py | 2 +- payment_multic_ux/models/account_payment.py | 11 +- payment_multic_ux/models/payment_provider.py | 8 +- .../models/payment_transaction.py | 6 +- website_multicompany/__manifest__.py | 22 +- website_multicompany/models/ir_http.py | 6 +- website_multicompany/models/website.py | 5 +- website_sale_multic_ux/__manifest__.py | 24 +-- website_sale_multic_ux/controllers/main.py | 10 +- website_sale_multicompany/__manifest__.py | 24 +-- .../controllers/portal.py | 83 ++++---- .../models/sale_order.py | 7 +- website_sale_multicompany/models/website.py | 7 +- .../__manifest__.py | 24 +-- .../models/sale_order.py | 15 +- .../models/website.py | 13 +- 34 files changed, 547 insertions(+), 527 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5c1bd68b..6fd938a9 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,7 +4,7 @@ exclude: | (?x) - + # We don't want to mess with tool-generated files .svg$|/tests/([^/]+/)?cassettes/|^.copier-answers.yml$|^.github/|^eslint.config.cjs|^prettier.config.cjs| # Library files can have extraneous formatting (even minimized) diff --git a/account_multicompany_ux/__manifest__.py b/account_multicompany_ux/__manifest__.py index ab2d79cf..a4818af5 100644 --- a/account_multicompany_ux/__manifest__.py +++ b/account_multicompany_ux/__manifest__.py @@ -18,29 +18,29 @@ # ############################################################################## { - 'name': 'Account Multicompany Usability', - 'version': "18.0.1.0.0", - 'author': 'ADHOC SA', - 'website': 'www.adhoc.com.ar', - 'license': 'AGPL-3', - 'depends': [ - 'account', - 'account_reports', + "name": "Account Multicompany Usability", + "version": "18.0.1.0.0", + "author": "ADHOC SA", + "website": "www.adhoc.com.ar", + "license": "AGPL-3", + "depends": [ + "account", + "account_reports", ], - 'data': [ - 'views/res_company_property_views.xml', - 'views/res_company_views.xml', - 'views/res_partner_views.xml', - 'views/product_category_views.xml', - 'views/product_template_views.xml', - 'views/product_product_views.xml', - 'views/account_journal_dashboard_views.xml', - 'wizards/account_change_company_views.xml', - 'views/account_move_views.xml', - 'security/account_multicompany_ux_security.xml', - 'security/ir.model.access.csv', + "data": [ + "views/res_company_property_views.xml", + "views/res_company_views.xml", + "views/res_partner_views.xml", + "views/product_category_views.xml", + "views/product_template_views.xml", + "views/product_product_views.xml", + "views/account_journal_dashboard_views.xml", + "wizards/account_change_company_views.xml", + "views/account_move_views.xml", + "security/account_multicompany_ux_security.xml", + "security/ir.model.access.csv", ], - 'demo': [], - 'installable': True, - 'auto_install': False, + "demo": [], + "installable": True, + "auto_install": False, } diff --git a/account_multicompany_ux/i18n/account_mutlicompany_usability.pot b/account_multicompany_ux/i18n/account_mutlicompany_usability.pot index 94a8551f..3195225a 100644 --- a/account_multicompany_ux/i18n/account_mutlicompany_usability.pot +++ b/account_multicompany_ux/i18n/account_mutlicompany_usability.pot @@ -240,4 +240,3 @@ msgstr "" #: model:ir.model,name:account_mutlicompany_usability.model_account_tax_code msgid "Tax Code" msgstr "" - diff --git a/account_multicompany_ux/models/account_account.py b/account_multicompany_ux/models/account_account.py index baf9737c..5fdbfebc 100644 --- a/account_multicompany_ux/models/account_account.py +++ b/account_multicompany_ux/models/account_account.py @@ -2,18 +2,19 @@ class AccountAccount(models.Model): - - _inherit = 'account.account' + _inherit = "account.account" def _compute_display_name(self): """ Agregamos sufijo de compañía en reportes financieros si hay más de una compañía seleccionada """ - if self._context.get('report_id') and len(self._context.get('company_ids', self.env.companies.ids)) > 1: + if self._context.get("report_id") and len(self._context.get("company_ids", self.env.companies.ids)) > 1: for account in self: if account.code: - company = self.env['res.company'].browse(self._context['allowed_company_ids'][0]) - account.display_name = f"{account.with_company(company).code} {account.name}{company.get_company_sufix()}" + company = self.env["res.company"].browse(self._context["allowed_company_ids"][0]) + account.display_name = ( + f"{account.with_company(company).code} {account.name}{company.get_company_sufix()}" + ) else: account.display_name = account.name else: diff --git a/account_multicompany_ux/models/account_journal.py b/account_multicompany_ux/models/account_journal.py index 2ecbfdf7..f09251e6 100644 --- a/account_multicompany_ux/models/account_journal.py +++ b/account_multicompany_ux/models/account_journal.py @@ -6,13 +6,12 @@ class AccountJournal(models.Model): + _inherit = "account.journal" - _inherit = 'account.journal' - - @api.depends('name', 'currency_id', 'company_id', 'company_id.currency_id') + @api.depends("name", "currency_id", "company_id", "company_id.currency_id") def _compute_display_name(self): """ - Este método lo que haría es agregar el nombre de la compañía entre paréntesis al final del nombre del diario + Este método lo que haría es agregar el nombre de la compañía entre paréntesis al final del nombre del diario cuando uno ingresa a la vista form esto lo hace en el nombre que está en el menú hamburguesa. en caso de que {journal.company_id.get_company_sufix()} sea False llamamos a super para mantener el comportamiento nativo de odoo diff --git a/account_multicompany_ux/models/account_move.py b/account_multicompany_ux/models/account_move.py index 95e224df..0125d378 100644 --- a/account_multicompany_ux/models/account_move.py +++ b/account_multicompany_ux/models/account_move.py @@ -2,19 +2,18 @@ # For copyright and license notices, see __manifest__.py file in module root # directory ############################################################################## -from odoo import api, models, fields, _ +from odoo import _, api, fields, models from odoo.exceptions import ValidationError class AccountMove(models.Model): - _inherit = 'account.move' + _inherit = "account.move" reversed_entry_id = fields.Many2one(check_company=False) company_id = fields.Many2one(tracking=True) - @api.constrains('company_id') + @api.constrains("company_id") def check_company(self): for move in self: if move.company_id.consolidation_company: - raise ValidationError(_( - 'You can not create entries on a consolidation company')) + raise ValidationError(_("You can not create entries on a consolidation company")) diff --git a/account_multicompany_ux/models/account_report.py b/account_multicompany_ux/models/account_report.py index 39902f64..b2eb6a34 100644 --- a/account_multicompany_ux/models/account_report.py +++ b/account_multicompany_ux/models/account_report.py @@ -2,14 +2,33 @@ # For copyright and license notices, see __manifest__.py file in module root # directory ############################################################################## -from odoo import models, fields +from odoo import models class AccountReport(models.Model): - _inherit = 'account.report' + _inherit = "account.report" - def _expand_unfoldable_line(self, expand_function_name, line_dict_id, groupby, options, progress, offset, horizontal_split_side, unfold_all_batch_data=None): - """ Agregamos sufijo de compañía en reportes financieros si hay más de una compañía seleccionada en el método _compute_display_name de account.account pero necesitamos agregar por contexto el id del reporte porque si no lo hacemos al momento de hacer un unfold de algún rubro en el reporte las cuentas se muestran sin dicho sufijo. Ver ticket 43453 para ver más info acerca de la funcionalidad que necesitamos. """ + def _expand_unfoldable_line( + self, + expand_function_name, + line_dict_id, + groupby, + options, + progress, + offset, + horizontal_split_side, + unfold_all_batch_data=None, + ): + """Agregamos sufijo de compañía en reportes financieros si hay más de una compañía seleccionada en el método _compute_display_name de account.account pero necesitamos agregar por contexto el id del reporte porque si no lo hacemos al momento de hacer un unfold de algún rubro en el reporte las cuentas se muestran sin dicho sufijo. Ver ticket 43453 para ver más info acerca de la funcionalidad que necesitamos.""" self = self.with_context(report_id=self.id) - return super()._expand_unfoldable_line(expand_function_name, line_dict_id, groupby, options, progress, offset, horizontal_split_side, unfold_all_batch_data) + return super()._expand_unfoldable_line( + expand_function_name, + line_dict_id, + groupby, + options, + progress, + offset, + horizontal_split_side, + unfold_all_batch_data, + ) diff --git a/account_multicompany_ux/models/product_category.py b/account_multicompany_ux/models/product_category.py index 279f7131..bdd782fe 100644 --- a/account_multicompany_ux/models/product_category.py +++ b/account_multicompany_ux/models/product_category.py @@ -6,37 +6,30 @@ class ProductCategory(models.Model): - - _name = 'product.category' - _inherit = ['product.category', 'res.company.property.mixin'] - _property_fields = {'property_account_income_categ_ids', 'property_account_expense_categ_ids'} - + _name = "product.category" + _inherit = ["product.category", "res.company.property.mixin"] + _property_fields = {"property_account_income_categ_ids", "property_account_expense_categ_ids"} property_account_income_categ_ids = fields.Many2many( - 'res.company.property', + "res.company.property", string="Income Accounts", - compute='_compute_properties', + compute="_compute_properties", ) property_account_expense_categ_ids = fields.Many2many( - 'res.company.property', + "res.company.property", string="Expense Accounts", - compute='_compute_properties', + compute="_compute_properties", ) @api.depends() def _compute_properties(self): - company_property = self.env['res.company.property'] + company_property = self.env["res.company.property"] property_fields = dict( - property_account_income_categ_ids=( - 'property_account_income_categ_id'), - property_account_expense_categ_ids=( - 'property_account_expense_categ_id'), + property_account_income_categ_ids=("property_account_income_categ_id"), + property_account_expense_categ_ids=("property_account_expense_categ_id"), ) for rec in self: - - company_properties = company_property.with_context( - active_model=self._name, - active_id=rec.id) + company_properties = company_property.with_context(active_model=self._name, active_id=rec.id) for newfield, oldfield in property_fields.items(): rec[newfield] = company_properties.with_context(property_field=oldfield)._get_companies() diff --git a/account_multicompany_ux/models/product_product.py b/account_multicompany_ux/models/product_product.py index 705e7bc0..0140f25b 100644 --- a/account_multicompany_ux/models/product_product.py +++ b/account_multicompany_ux/models/product_product.py @@ -8,39 +8,35 @@ class ProductProduct(models.Model): """Overwrite of computed fields using product_tmpl_id instead of id""" - _name = 'product.product' - _inherit = ['product.product', 'res.company.property.mixin'] - _property_fields = {'property_account_income_ids', 'property_account_expense_ids', 'standard_price_ids'} - + _name = "product.product" + _inherit = ["product.product", "res.company.property.mixin"] + _property_fields = {"property_account_income_ids", "property_account_expense_ids", "standard_price_ids"} property_account_income_ids = fields.Many2many( - 'res.company.property', + "res.company.property", string="Income Accounts", - compute='_compute_properties', + compute="_compute_properties", ) property_account_expense_ids = fields.Many2many( - 'res.company.property', + "res.company.property", string="Expense Accounts", - compute='_compute_properties', + compute="_compute_properties", ) standard_price_ids = fields.Many2many( - 'res.company.property', + "res.company.property", string="Accounting Costs", - compute='_compute_properties', + compute="_compute_properties", ) @api.depends() def _compute_properties(self): - company_property = self.env['res.company.property'] + company_property = self.env["res.company.property"] property_fields = dict( - property_account_income_ids='property_account_income_id', - property_account_expense_ids='property_account_expense_id', - standard_price_ids='standard_price', + property_account_income_ids="property_account_income_id", + property_account_expense_ids="property_account_expense_id", + standard_price_ids="standard_price", ) for rec in self: - company_properties = company_property.with_context( - active_model='product.product', - active_id=rec.id) + company_properties = company_property.with_context(active_model="product.product", active_id=rec.id) for newfield, oldfield in property_fields.items(): - rec[newfield] = company_properties.with_context( - property_field=oldfield)._get_companies() + rec[newfield] = company_properties.with_context(property_field=oldfield)._get_companies() diff --git a/account_multicompany_ux/models/product_template.py b/account_multicompany_ux/models/product_template.py index be283a25..f78f6b94 100644 --- a/account_multicompany_ux/models/product_template.py +++ b/account_multicompany_ux/models/product_template.py @@ -6,43 +6,37 @@ class ProductTemplate(models.Model): - - _name = 'product.template' - _inherit = ['product.template', 'res.company.property.mixin'] - _property_fields = {'property_account_income_ids', 'property_account_expense_ids', 'standard_price_ids'} + _name = "product.template" + _inherit = ["product.template", "res.company.property.mixin"] + _property_fields = {"property_account_income_ids", "property_account_expense_ids", "standard_price_ids"} property_account_income_ids = fields.Many2many( - 'res.company.property', + "res.company.property", string="Income Accounts", - compute='_compute_properties', + compute="_compute_properties", ) property_account_expense_ids = fields.Many2many( - 'res.company.property', + "res.company.property", string="Expense Accounts", - compute='_compute_properties', + compute="_compute_properties", ) standard_price_ids = fields.Many2many( - 'res.company.property', + "res.company.property", string="Accounting Costs", - compute='_compute_properties', + compute="_compute_properties", ) @api.depends() def _compute_properties(self): - company_property = self.env['res.company.property'] + company_property = self.env["res.company.property"] property_fields = dict( - property_account_income_ids='property_account_income_id', - property_account_expense_ids='property_account_expense_id', - standard_price_ids='standard_price', + property_account_income_ids="property_account_income_id", + property_account_expense_ids="property_account_expense_id", + standard_price_ids="standard_price", ) for rec in self: - company_properties = company_property.with_context( - active_model='product.template', - active_id=rec.id) + company_properties = company_property.with_context(active_model="product.template", active_id=rec.id) values = {} for newfield, oldfield in property_fields.items(): - values.update({ - newfield: company_properties.with_context( - property_field=oldfield)._get_companies() - }) + values.update({newfield: company_properties.with_context(property_field=oldfield)._get_companies()}) rec.update(values) diff --git a/account_multicompany_ux/models/res_company.py b/account_multicompany_ux/models/res_company.py index 14348f3f..3e9a9edf 100644 --- a/account_multicompany_ux/models/res_company.py +++ b/account_multicompany_ux/models/res_company.py @@ -2,33 +2,31 @@ # For copyright and license notices, see __manifest__.py file in module root # directory ############################################################################## -from odoo import fields, models -from odoo import tools +from odoo import fields, models, tools class ResCompany(models.Model): - - _inherit = 'res.company' + _inherit = "res.company" short_name = fields.Char( - help='Short name used to identify this company', + help="Short name used to identify this company", ) consolidation_company = fields.Boolean( - help='Journal entries are not allowed on consolidation companies. (so' - ' invoices, payments, etc neither)' + help="Journal entries are not allowed on consolidation companies. (so" " invoices, payments, etc neither)" ) # TODO habria que terminar de ver si esta bien este cache o en realidad para # ser mas performante no hay que usar nada de self - @tools.ormcache_context('self.env.uid', 'self.name', 'self.short_name', keys=('no_company_sufix',)) + @tools.ormcache_context("self.env.uid", "self.name", "self.short_name", keys=("no_company_sufix",)) def get_company_sufix(self): - """ Cuando pedimos para un registro que no tiene cia no queremos que + """Cuando pedimos para un registro que no tiene cia no queremos que ensure_one arroje error """ - condition = \ - len(self) != 1 or \ - self._context.get('no_company_sufix') or \ - not self.env.user.has_group('base.group_multi_company') + condition = ( + len(self) != 1 + or self._context.get("no_company_sufix") + or not self.env.user.has_group("base.group_multi_company") + ) - return '' if condition else ' (%s)' % (self.short_name or self.name) + return "" if condition else " (%s)" % (self.short_name or self.name) diff --git a/account_multicompany_ux/models/res_company_property.py b/account_multicompany_ux/models/res_company_property.py index e44a6cab..221d56ea 100644 --- a/account_multicompany_ux/models/res_company_property.py +++ b/account_multicompany_ux/models/res_company_property.py @@ -4,15 +4,11 @@ ############################################################################## import logging from ast import literal_eval -from psycopg2 import sql from odoo import _, api, fields, models, tools from odoo.exceptions import UserError -from odoo import tools -from lxml import etree -from ast import literal_eval -import logging -import json +from psycopg2 import sql + _logger = logging.getLogger(__name__) @@ -21,20 +17,21 @@ class ResCompanyProperty(models.Model): We dont use res.company because most user dont' have access rights to edit it """ + _name = "res.company.property" _description = "Company Property" _auto = False _check_company_auto = True # _rec_name = 'display_name' _depends = { - 'res.company': [ - 'id', + "res.company": [ + "id", ], } company_id = fields.Many2one( - 'res.company', - 'Company', + "res.company", + "Company", required=True, ) @@ -49,84 +46,78 @@ def init(self): res_company c """ - cr.execute( - sql.SQL("CREATE OR REPLACE VIEW {} AS ({})").format( - sql.Identifier(self._table), - sql.SQL(query) - ) - ) + cr.execute(sql.SQL("CREATE OR REPLACE VIEW {} AS ({})").format(sql.Identifier(self._table), sql.SQL(query))) property_field = fields.Char( - compute='_compute_property_field', + compute="_compute_property_field", ) - property_domain = fields.Json(compute='_compute_property_account_domain') + property_domain = fields.Json(compute="_compute_property_account_domain") property_account_id = fields.Many2one( - 'account.account', - string='Account', - compute='_compute_property_account', - inverse='_inverse_property_account', + "account.account", + string="Account", + compute="_compute_property_account", + inverse="_inverse_property_account", ) property_term_id = fields.Many2one( - 'account.payment.term', - string='Payment Term', - compute='_compute_property_term', - inverse='_inverse_property_term', + "account.payment.term", + string="Payment Term", + compute="_compute_property_term", + inverse="_inverse_property_term", ) property_position_id = fields.Many2one( - 'account.fiscal.position', - string='Fiscal Position', - compute='_compute_property_position', - inverse='_inverse_property_position', + "account.fiscal.position", + string="Fiscal Position", + compute="_compute_property_position", + inverse="_inverse_property_position", ) property_pricelist_id = fields.Many2one( - 'product.pricelist', - string='Pricelist', - compute='_compute_property_pricelist', - inverse='_inverse_property_pricelist', + "product.pricelist", + string="Pricelist", + compute="_compute_property_pricelist", + inverse="_inverse_property_pricelist", ) standard_price = fields.Float( string="standard_price", - compute='_compute_property_standard_price', - inverse='_inverse_property_standard_price', - digits='Product Price', + compute="_compute_property_standard_price", + inverse="_inverse_property_standard_price", + digits="Product Price", ) # display_name = fields.Char( # compute='_compute_display_name' # ) - @api.onchange('property_field', 'company_id') + @api.onchange("property_field", "company_id") def _onchange_property_field(self): - return {'domain': {'property_account_id': [('company_id', '=', False)]}} + return {"domain": {"property_account_id": [("company_id", "=", False)]}} @api.model def _get_companies(self): domain = [] comodel = self._get_property_comodel() - self.invalidate_model(['property_account_id']) - if comodel in ['account.account']: - domain = [('company_id.consolidation_company', '=', False)] + self.invalidate_model(["property_account_id"]) + if comodel in ["account.account"]: + domain = [("company_id.consolidation_company", "=", False)] return self.search(domain) @api.model def action_company_properties(self): - property_field = self._context.get('property_field', False) + property_field = self._context.get("property_field", False) if not property_field: return True company_properties = self._get_companies() - action_read = self.env["ir.actions.actions"]._for_xml_id( - 'account_multicompany_ux.action_res_company_property') + action_read = self.env["ir.actions.actions"]._for_xml_id("account_multicompany_ux.action_res_company_property") # do this because raise an error if came from a view # with group_by activated ctx = self._context.copy() - ctx.pop('group_by', None) - action_read['context'] = ctx - action_read['domain'] = [('id', 'in', company_properties.ids)] + ctx.pop("group_by", None) + action_read["context"] = ctx + action_read["domain"] = [("id", "in", company_properties.ids)] return action_read @api.model def _get_property_comodel(self): - property_field = self._context.get('property_field') + property_field = self._context.get("property_field") record = self._get_record() if record: field = self._get_record()._fields.get(property_field) @@ -135,36 +126,34 @@ def _get_property_comodel(self): @api.model def _get_record(self): context = self._context - active_model = context.get('active_model') - active_id = context.get('active_id') - property_field = context.get('property_field') + active_model = context.get("active_model") + active_id = context.get("active_id") + property_field = context.get("property_field") if not property_field or not active_id or not active_model: - _logger.warning( - 'Could not get property record from context %s' % context) + _logger.warning("Could not get property record from context %s" % context) return False return self.with_company(self.id).env[active_model].browse(active_id) @api.model def _get_company_property_field(self): comodel = self._get_property_comodel() - if comodel == 'account.account': - company_property_field = 'property_account_id' - elif comodel == 'account.fiscal.position': - company_property_field = 'property_position_id' - elif comodel == 'account.payment.term': - company_property_field = 'property_term_id' - elif comodel == 'product.pricelist': - company_property_field = 'property_pricelist_id' + if comodel == "account.account": + company_property_field = "property_account_id" + elif comodel == "account.fiscal.position": + company_property_field = "property_position_id" + elif comodel == "account.payment.term": + company_property_field = "property_term_id" + elif comodel == "product.pricelist": + company_property_field = "property_pricelist_id" else: - property_field = self._context.get('property_field') - if property_field == 'standard_price': - company_property_field = 'standard_price' + property_field = self._context.get("property_field") + if property_field == "standard_price": + company_property_field = "standard_price" else: - raise UserError( - _('Property for model %s not implemented yet', comodel)) + raise UserError(_("Property for model %s not implemented yet", comodel)) return company_property_field - @api.depends('company_id', 'property_field') + @api.depends("company_id", "property_field") def _compute_display_name(self): """ No llamamos a super porque tendriamos que igualmente hacer un read @@ -180,31 +169,23 @@ def _compute_display_name(self): rec.invalidate_recordset([company_property_field]) rec.modified([company_property_field]) - company_field = getattr( - rec.with_context(no_company_sufix=True), - company_property_field) + company_field = getattr(rec.with_context(no_company_sufix=True), company_property_field) if type(company_field) is float: - precision_digits = self.env['decimal.precision'].precision_get( - 'Product Price') + precision_digits = self.env["decimal.precision"].precision_get("Product Price") # por alguna razon el float_round no nos está funcionando # y usamos round directamente (por ej. para valor 42,66) - company_field = company_field and round( - company_field, precision_digits) + company_field = company_field and round(company_field, precision_digits) # company_field = company_field and float_round( # company_field, precision_digits=precision_digits) - display_name = '%s%s' % ( - company_field or _('None'), - rec.company_id.get_company_sufix()) + display_name = "%s%s" % (company_field or _("None"), rec.company_id.get_company_sufix()) else: - display_name = '%s%s' % ( - company_field.display_name or _('None'), - rec.company_id.get_company_sufix()) + display_name = "%s%s" % (company_field.display_name or _("None"), rec.company_id.get_company_sufix()) rec.display_name = display_name - @api.depends_context('property_field') + @api.depends_context("property_field") def _compute_property_field(self): for record in self: - record.property_field = self._context.get('property_field', '') + record.property_field = self._context.get("property_field", "") def _get_property_value(self): self.ensure_one() @@ -212,62 +193,63 @@ def _get_property_value(self): record = self._get_record() if not record or not property_field: return False - return getattr( - record, - property_field) + return getattr(record, property_field) - @api.depends('property_field') + @api.depends("property_field") def _compute_property_standard_price(self): for record in self: - if record.property_field == 'standard_price': + if record.property_field == "standard_price": record.standard_price = record._get_property_value() else: record.standard_price = False - @api.depends('property_field', 'company_id') + @api.depends("property_field", "company_id") def _compute_property_account_domain(self): for record in self: - if record._get_property_comodel() == 'account.account': - domain = self._context.get('property_domain') + if record._get_property_comodel() == "account.account": + domain = self._context.get("property_domain") if not domain: field = record._get_record()._fields.get(record.property_field) try: domain = literal_eval(field.domain) except: domain = [] - record.property_domain = ['|', ('company_id', '=', False), ('company_id', '=', record.company_id.id)] + domain + record.property_domain = [ + "|", + ("company_id", "=", False), + ("company_id", "=", record.company_id.id), + ] + domain else: record.property_domain = [] - - @api.depends('property_field') + @api.depends("property_field") def _compute_property_account(self): for record in self: - if record._get_property_comodel() == 'account.account': + if record._get_property_comodel() == "account.account": record.property_account_id = record._get_property_value() else: record.property_account_id = False - @api.depends('property_field') + @api.depends("property_field") def _compute_property_position(self): for record in self: - if record._get_property_comodel() == 'account.fiscal.position': + if record._get_property_comodel() == "account.fiscal.position": record.property_position_id = record._get_property_value() else: record.property_position_id = False - @api.depends('property_field') + @api.depends("property_field") def _compute_property_term(self): for record in self: - if record._get_property_comodel() == 'account.payment.term': + if record._get_property_comodel() == "account.payment.term": record.property_term_id = record._get_property_value() else: record.property_term_id = False - @api.depends('property_field') + @api.depends("property_field") def _compute_property_pricelist(self): for record in self: - if record._get_property_comodel() == 'product.pricelist': + if record._get_property_comodel() == "product.pricelist": record.property_pricelist_id = record._get_property_value() else: record.property_pricelist_id = False @@ -278,10 +260,7 @@ def _set_property_value(self, value): property_field = self.property_field if not record or not property_field: return True - setattr( - record, - property_field, - value) + setattr(record, property_field, value) def _inverse_property_account(self): for rec in self: @@ -304,7 +283,7 @@ def _inverse_property_standard_price(self): rec._set_property_value(rec.standard_price) def web_read(self, specification): - fields_to_read = list(specification) or {'id'} - if fields_to_read == ['display_name']: - self.env['res.company.property'].invalidate_model(['display_name']) + fields_to_read = list(specification) or {"id"} + if fields_to_read == ["display_name"]: + self.env["res.company.property"].invalidate_model(["display_name"]) return super().web_read(specification) diff --git a/account_multicompany_ux/models/res_company_property_mixin.py b/account_multicompany_ux/models/res_company_property_mixin.py index 6ad63b75..f8100898 100644 --- a/account_multicompany_ux/models/res_company_property_mixin.py +++ b/account_multicompany_ux/models/res_company_property_mixin.py @@ -2,39 +2,36 @@ class ResCompanyPropertyMixin(models.AbstractModel): - _name = "res.company.property.mixin" _description = "Company property mixin abstract" - def web_read(self, specification): - """ Esto lo agregamos para propagar el contexto del active_id """ - fields_to_read = set(specification) or {'id'} - if hasattr(self, '_property_fields'): + """Esto lo agregamos para propagar el contexto del active_id""" + fields_to_read = set(specification) or {"id"} + if hasattr(self, "_property_fields"): fields_to_add_context = self._property_fields.intersection(fields_to_read) for field in fields_to_add_context: - specification[field]['context'].update({'active_id': self._ids}) + specification[field]["context"].update({"active_id": self._ids}) return super().web_read(specification) def action_company_properties(self): self.ensure_one() - action = self.env['res.company.property'].with_context( - active_model=self._name, active_id=self.id - ).action_company_properties() - if self._context.get('property_field') == 'property_account_position_id': - view_id = self.env.ref('account_multicompany_ux.view_property_position_id_form').id - elif self._context.get('property_field') == 'property_payment_term_id': - view_id = self.env.ref('account_multicompany_ux.view_property_term_id_form').id - elif self._context.get('property_field') == 'property_product_pricelist': - view_id = self.env.ref('account_multicompany_ux.view_property_pricelist_id_form').id - elif self._context.get('property_field') == 'property_supplier_payment_term_id': - view_id = self.env.ref('account_multicompany_ux.view_property_term_id_form').id - elif self._context.get('property_field').startswith('property_account'): - view_id = self.env.ref('account_multicompany_ux.view_property_account_id_form').id + action = ( + self.env["res.company.property"] + .with_context(active_model=self._name, active_id=self.id) + .action_company_properties() + ) + if self._context.get("property_field") == "property_account_position_id": + view_id = self.env.ref("account_multicompany_ux.view_property_position_id_form").id + elif self._context.get("property_field") == "property_payment_term_id": + view_id = self.env.ref("account_multicompany_ux.view_property_term_id_form").id + elif self._context.get("property_field") == "property_product_pricelist": + view_id = self.env.ref("account_multicompany_ux.view_property_pricelist_id_form").id + elif self._context.get("property_field") == "property_supplier_payment_term_id": + view_id = self.env.ref("account_multicompany_ux.view_property_term_id_form").id + elif self._context.get("property_field").startswith("property_account"): + view_id = self.env.ref("account_multicompany_ux.view_property_account_id_form").id else: - view_id = self.env.ref('account_multicompany_ux.view_standard_price_form').id - action['views'] = [[view_id, 'list']] + view_id = self.env.ref("account_multicompany_ux.view_standard_price_form").id + action["views"] = [[view_id, "list"]] return action - - - diff --git a/account_multicompany_ux/models/res_partner.py b/account_multicompany_ux/models/res_partner.py index b7ea65b8..733dbad0 100644 --- a/account_multicompany_ux/models/res_partner.py +++ b/account_multicompany_ux/models/res_partner.py @@ -2,65 +2,68 @@ # For copyright and license notices, see __manifest__.py file in module root # directory ############################################################################## -from odoo import fields, models - import logging +from odoo import fields, models + _logger = logging.getLogger(__name__) -class ResPartner(models.Model): - _name = 'res.partner' - _inherit = ['res.partner', 'res.company.property.mixin'] - _property_fields = {'property_account_receivable_ids', 'property_account_payable_ids', 'property_account_position_ids', - 'property_payment_term_ids', 'property_supplier_payment_term_ids', 'property_product_pricelist_ids'} +class ResPartner(models.Model): + _name = "res.partner" + _inherit = ["res.partner", "res.company.property.mixin"] + _property_fields = { + "property_account_receivable_ids", + "property_account_payable_ids", + "property_account_position_ids", + "property_payment_term_ids", + "property_supplier_payment_term_ids", + "property_product_pricelist_ids", + } property_account_receivable_ids = fields.Many2many( - 'res.company.property', + "res.company.property", string="Accounts Receivable", - compute='_compute_properties', + compute="_compute_properties", ) property_account_payable_ids = fields.Many2many( - 'res.company.property', + "res.company.property", string="Accounts Payable", - compute='_compute_properties', + compute="_compute_properties", ) property_account_position_ids = fields.Many2many( - 'res.company.property', + "res.company.property", string="Fiscal Positions", - compute='_compute_properties', + compute="_compute_properties", ) property_payment_term_ids = fields.Many2many( - 'res.company.property', - string='Customer Payment Term', - compute='_compute_properties', + "res.company.property", + string="Customer Payment Term", + compute="_compute_properties", ) property_supplier_payment_term_ids = fields.Many2many( - 'res.company.property', - string='Supplier Payment Terms', - compute='_compute_properties', + "res.company.property", + string="Supplier Payment Terms", + compute="_compute_properties", ) property_product_pricelist_ids = fields.Many2many( - 'res.company.property', - string='Sale Pricelists', - compute='_compute_properties', + "res.company.property", + string="Sale Pricelists", + compute="_compute_properties", ) def _compute_properties(self): property_fields = dict( - property_account_receivable_ids='property_account_receivable_id', - property_account_payable_ids='property_account_payable_id', - property_account_position_ids='property_account_position_id', - property_payment_term_ids='property_payment_term_id', - property_supplier_payment_term_ids=( - 'property_supplier_payment_term_id' - ), - property_product_pricelist_ids='property_product_pricelist', + property_account_receivable_ids="property_account_receivable_id", + property_account_payable_ids="property_account_payable_id", + property_account_position_ids="property_account_position_id", + property_payment_term_ids="property_payment_term_id", + property_supplier_payment_term_ids=("property_supplier_payment_term_id"), + property_product_pricelist_ids="property_product_pricelist", ) for rec in self: - company_properties = self.env['res.company.property'].with_context( - active_model=self._name, active_id=rec.id) + company_properties = self.env["res.company.property"].with_context( + active_model=self._name, active_id=rec.id + ) for newfield, oldfield in property_fields.items(): - rec[newfield] = company_properties.with_context( - property_field=oldfield)._get_companies() - + rec[newfield] = company_properties.with_context(property_field=oldfield)._get_companies() diff --git a/account_multicompany_ux/tests/test_account_multicompany_ux_unit_test.py b/account_multicompany_ux/tests/test_account_multicompany_ux_unit_test.py index d0eec249..c782a63b 100644 --- a/account_multicompany_ux/tests/test_account_multicompany_ux_unit_test.py +++ b/account_multicompany_ux/tests/test_account_multicompany_ux_unit_test.py @@ -1,86 +1,109 @@ -from odoo.tests.common import TransactionCase from odoo import Command, fields -from datetime import timedelta +from odoo.tests.common import TransactionCase class TestAccountMulticompanyUxUnitTest(TransactionCase): - def setUp(self): super().setUp() self.today = fields.Date.today() - self.first_company = self.env['res.company'].search([], limit=1) - self.second_company = self.env['res.company'].search([('id', '!=', self.first_company.id)], limit=1) + self.first_company = self.env["res.company"].search([], limit=1) + self.second_company = self.env["res.company"].search([("id", "!=", self.first_company.id)], limit=1) if not self.second_company: - self.second_company = self.env['res.company'].create({'name': 'Test Company 2'}) - - self.partner_ri = self.env['res.partner'].search([], limit=1) + self.second_company = self.env["res.company"].create({"name": "Test Company 2"}) - self.first_company_journal = self.env['account.journal'].search([('company_id', '=', self.first_company.id), ('type', '=', 'sale')], limit=1) - self.second_company_journal = self.env['account.journal'].search([('company_id', '=', self.second_company.id), ('type', '=', 'sale')], limit=1) + self.partner_ri = self.env["res.partner"].search([], limit=1) + + self.first_company_journal = self.env["account.journal"].search( + [("company_id", "=", self.first_company.id), ("type", "=", "sale")], limit=1 + ) + self.second_company_journal = self.env["account.journal"].search( + [("company_id", "=", self.second_company.id), ("type", "=", "sale")], limit=1 + ) if not self.second_company_journal: - - a_sale = self.env['account.account'].create({ - 'code': 'X2020', - 'name': 'Product Sales - (test)', - 'account_type': 'income', - 'company_ids': [self.second_company.id], - }) + a_sale = self.env["account.account"].create( + { + "code": "X2020", + "name": "Product Sales - (test)", + "account_type": "income", + "company_ids": [self.second_company.id], + } + ) + + self.env["account.account"].create( + { + "code": "X2021", + "name": "Product Sales Receivable - (test)", + "account_type": "asset_receivable", + "company_ids": [self.second_company.id], + } + ) - self.env['account.account'].create({ - 'code': 'X2021', - 'name': 'Product Sales Receivable - (test)', - 'account_type': 'asset_receivable', - 'company_ids': [self.second_company.id], - }) + self.second_company_journal = self.env["account.journal"].create( + { + "name": "Second Customer Invoices - Test", + "code": "TINV", + "type": "sale", + "default_account_id": a_sale.id, + "company_id": self.second_company.id, + } + ) - self.second_company_journal = self.env['account.journal'].create({ - 'name': 'Second Customer Invoices - Test', - 'code': 'TINV', - 'type': 'sale', - 'default_account_id': a_sale.id, - 'company_id': self.second_company.id, - }) - - self.bank_1 = self.env['res.partner.bank'].search([('company_id','=', False)], limit=1) - self.bank_1.write({'partner_id': self.first_company.partner_id.id}) + self.bank_1 = self.env["res.partner.bank"].search([("company_id", "=", False)], limit=1) + self.bank_1.write({"partner_id": self.first_company.partner_id.id}) self.bank_1.company_id = self.first_company.id self.env.company = self.first_company def test_multicompany_sale_order(self): """Cambio de compañía de una factura que cuenta con res partner bank seteado para la compañia original""" - invoice = self.env['account.move'].create({ - 'partner_id': self.partner_ri.id, - 'invoice_date': self.today, - 'move_type': 'out_invoice', - 'journal_id': self.first_company_journal.id, - 'company_id': self.first_company.id, - 'partner_bank_id': self.bank_1.id, - 'invoice_line_ids': [ - Command.create({ - 'product_id': self.env.ref('product.product_product_16').id, - 'quantity': 1, - 'price_unit': 100, - }), - ], - }) + invoice = self.env["account.move"].create( + { + "partner_id": self.partner_ri.id, + "invoice_date": self.today, + "move_type": "out_invoice", + "journal_id": self.first_company_journal.id, + "company_id": self.first_company.id, + "partner_bank_id": self.bank_1.id, + "invoice_line_ids": [ + Command.create( + { + "product_id": self.env.ref("product.product_product_16").id, + "quantity": 1, + "price_unit": 100, + } + ), + ], + } + ) - acc = self.env['account.change.company'].create({ - 'move_id': invoice.id, - 'company_ids': [self.first_company.id, self.second_company.id], - 'company_id': self.second_company.id, - 'journal_id': self.second_company_journal.id - }) + acc = self.env["account.change.company"].create( + { + "move_id": invoice.id, + "company_ids": [self.first_company.id, self.second_company.id], + "company_id": self.second_company.id, + "journal_id": self.second_company_journal.id, + } + ) acc.change_company() - self.assertEqual(invoice.partner_bank_id.id, False , "No se realizo de forma correcta el cambio partner_bank_id al cambiar la compañia") - acc = self.env['account.change.company'].create({ - 'move_id': invoice.id, - 'company_ids': [self.first_company.id, self.second_company.id], - 'company_id': self.first_company.id, - 'journal_id': self.first_company_journal.id - }) + self.assertEqual( + invoice.partner_bank_id.id, + False, + "No se realizo de forma correcta el cambio partner_bank_id al cambiar la compañia", + ) + acc = self.env["account.change.company"].create( + { + "move_id": invoice.id, + "company_ids": [self.first_company.id, self.second_company.id], + "company_id": self.first_company.id, + "journal_id": self.first_company_journal.id, + } + ) acc.change_company() invoice._compute_bank_partner_id() invoice._compute_partner_bank_id() - self.assertEqual(invoice.partner_bank_id.id, self.bank_1.id , "No se realizo de forma correcta el cambio partner_bank_id al cambiar la compañia") + self.assertEqual( + invoice.partner_bank_id.id, + self.bank_1.id, + "No se realizo de forma correcta el cambio partner_bank_id al cambiar la compañia", + ) invoice.action_post() diff --git a/account_multicompany_ux/views/res_company_property_views.xml b/account_multicompany_ux/views/res_company_property_views.xml index 4ba3ad8f..56808676 100644 --- a/account_multicompany_ux/views/res_company_property_views.xml +++ b/account_multicompany_ux/views/res_company_property_views.xml @@ -55,7 +55,7 @@ - + res.company.property.form res.company.property @@ -66,7 +66,7 @@ - + Company Properties res.company.property diff --git a/account_multicompany_ux/wizards/account_change_company.py b/account_multicompany_ux/wizards/account_change_company.py index 65785954..5a32a75f 100644 --- a/account_multicompany_ux/wizards/account_change_company.py +++ b/account_multicompany_ux/wizards/account_change_company.py @@ -2,57 +2,62 @@ # For copyright and license notices, see __manifest__.py file in module root # directory ############################################################################## -from odoo import fields, models, api, _ +from odoo import api, fields, models class AccountChangeCurrency(models.TransientModel): - _name = 'account.change.company' - _description = 'Change Company' + _name = "account.change.company" + _description = "Change Company" @api.model def get_move(self): - move = self.env['account.move'].browse( - self._context.get('active_id', False)) + move = self.env["account.move"].browse(self._context.get("active_id", False)) return move - move_id = fields.Many2one('account.move', default=get_move) - company_ids = fields.Many2many('res.company', string='Companies', compute='_compute_company_ids') + move_id = fields.Many2one("account.move", default=get_move) + company_ids = fields.Many2many("res.company", string="Companies", compute="_compute_company_ids") company_id = fields.Many2one( - 'res.company', required=True, ondelete='cascade', - compute='_compute_company', store=True, readonly=False) + "res.company", required=True, ondelete="cascade", compute="_compute_company", store=True, readonly=False + ) journal_id = fields.Many2one( - 'account.journal', required=True, ondelete='cascade', domain="[('id', 'in', suitable_journal_ids)]", - store=True, compute='_compute_journal', readonly=False) + "account.journal", + required=True, + ondelete="cascade", + domain="[('id', 'in', suitable_journal_ids)]", + store=True, + compute="_compute_journal", + readonly=False, + ) suitable_journal_ids = fields.Many2many( - 'account.journal', - compute='_compute_suitable_journal_ids', + "account.journal", + compute="_compute_suitable_journal_ids", ) - @api.depends('move_id') - @api.depends_context('allowed_company_ids') + @api.depends("move_id") + @api.depends_context("allowed_company_ids") def _compute_company_ids(self): self.company_ids = self.env.companies - self.move_id.company_id - @api.depends('company_ids') + @api.depends("company_ids") def _compute_company(self): for rec in self: rec.company_id = self.company_ids[:1] - @api.depends('suitable_journal_ids') + @api.depends("suitable_journal_ids") def _compute_journal(self): for rec in self: rec.journal_id = rec.suitable_journal_ids[:1] - @api.depends('move_id', 'company_id') + @api.depends("move_id", "company_id") def _compute_suitable_journal_ids(self): """ We override this method to add filter by companies in the env instead of the company of the user For this to work the pr is needed https://github.com/odoo/odoo/pull """ for rec in self: - journal_type = rec.move_id.invoice_filter_type_domain or 'general' - domain = [('company_id', '=', rec.company_id._origin.id), ('type', '=', journal_type)] - rec.suitable_journal_ids = self.env['account.journal'].search(domain) + journal_type = rec.move_id.invoice_filter_type_domain or "general" + domain = [("company_id", "=", rec.company_id._origin.id), ("type", "=", journal_type)] + rec.suitable_journal_ids = self.env["account.journal"].search(domain) def change_company(self): self.ensure_one() @@ -60,33 +65,51 @@ def change_company(self): original_payment_term = False # odoo no permite modificar diario si hay name, esto no es del todo correcto para facturas de proveedor con manual number y de hecho deberiamos # ver de cambiarlo en el codigo original, por ahora lo permitimos desde aca haciendo backup del nro y restaurando si corresponde - if self.move_id._fields.get('l10n_latam_manual_document_number') and self.move_id.l10n_latam_manual_document_number and self.move_id.name: + if ( + self.move_id._fields.get("l10n_latam_manual_document_number") + and self.move_id.l10n_latam_manual_document_number + and self.move_id.name + ): old_name = self.move_id.name - self.move_id.name = '/' + self.move_id.name = "/" old_doc_type = False - if self.move_id._fields.get('l10n_latam_document_type_id') and self.move_id.l10n_latam_manual_document_number: + if self.move_id._fields.get("l10n_latam_document_type_id") and self.move_id.l10n_latam_manual_document_number: old_doc_type = self.move_id.l10n_latam_document_type_id self.move_id.invoice_line_ids.tax_ids = False # si el payment term tiene compañía y es distinta a la que elegimos, forzamos recomputo - if self.move_id.invoice_payment_term_id.company_id and self.move_id.invoice_payment_term_id.company_id != self.company_id: + if ( + self.move_id.invoice_payment_term_id.company_id + and self.move_id.invoice_payment_term_id.company_id != self.company_id + ): # lo tenemos que hacer antes del write sino se obtiene mensaje "Operación no válida. Empresas incompatibles con los registros" self.move_id.with_company(self.move_id.company_id)._compute_invoice_payment_term_id() elif not self.move_id.invoice_payment_term_id.company_id: original_payment_term = self.move_id.invoice_payment_term_id self.move_id.invoice_payment_term_id = False invoice_payment_term_id = False - if self.move_id.is_purchase_document() and self.move_id._origin.partner_id and (not self.move_id.invoice_payment_term_id.company_id or self.move_id.invoice_payment_term_id.company_id == self.move_id.company_id): + if ( + self.move_id.is_purchase_document() + and self.move_id._origin.partner_id + and ( + not self.move_id.invoice_payment_term_id.company_id + or self.move_id.invoice_payment_term_id.company_id == self.move_id.company_id + ) + ): # esto lo hacemos porque sino el write borra el invoice_payment_term_id en facturas de proveedor si en invoice_payment_term_id no tiene compañía invoice_payment_term_id = self.move_id.invoice_payment_term_id - self.move_id.with_context(skip_invoice_sync=True).write({ - 'partner_bank_id': False, - 'company_id': self.company_id.id, - 'journal_id': self.journal_id.id, - }) + self.move_id.with_context(skip_invoice_sync=True).write( + { + "partner_bank_id": False, + "company_id": self.company_id.id, + "journal_id": self.journal_id.id, + } + ) if invoice_payment_term_id: self.move_id.invoice_payment_term_id = invoice_payment_term_id - without_product = self.move_id.line_ids.filtered(lambda line : line.display_type == 'product' and not line.product_id) + without_product = self.move_id.line_ids.filtered( + lambda line: line.display_type == "product" and not line.product_id + ) (self.move_id.line_ids - without_product).with_company(self.company_id.id)._compute_account_id() for line in without_product: line.account_id = line.move_id.journal_id.default_account_id @@ -95,7 +118,9 @@ def change_company(self): self.move_id.line_ids.with_company(self.company_id.id)._compute_tax_ids() self.move_id._compute_partner_bank_id() - for invoice_line in self.move_id.invoice_line_ids.filtered(lambda x: not x.product_id).with_company(self.company_id.id): + for invoice_line in self.move_id.invoice_line_ids.filtered(lambda x: not x.product_id).with_company( + self.company_id.id + ): invoice_line.tax_ids = invoice_line._get_computed_taxes() if old_doc_type and old_doc_type in self.move_id.l10n_latam_available_document_type_ids: self.move_id.l10n_latam_document_type_id = old_doc_type diff --git a/payment_multic_ux/__manifest__.py b/payment_multic_ux/__manifest__.py index 78199343..cb4e9329 100644 --- a/payment_multic_ux/__manifest__.py +++ b/payment_multic_ux/__manifest__.py @@ -18,16 +18,16 @@ # ############################################################################## { - 'name': 'Payment Multicompany Usability', - 'version': "18.0.1.0.0", - 'author': 'ADHOC SA', - 'website': 'www.adhoc.com.ar', - 'license': 'AGPL-3', - 'depends': [ - 'account_payment', + "name": "Payment Multicompany Usability", + "version": "18.0.1.0.0", + "author": "ADHOC SA", + "website": "www.adhoc.com.ar", + "license": "AGPL-3", + "depends": [ + "account_payment", ], - 'data': [], - 'demo': [], - 'installable': True, - 'auto_install': False, + "data": [], + "demo": [], + "installable": True, + "auto_install": False, } diff --git a/payment_multic_ux/models/__init__.py b/payment_multic_ux/models/__init__.py index 01222184..3daf02d3 100644 --- a/payment_multic_ux/models/__init__.py +++ b/payment_multic_ux/models/__init__.py @@ -1,3 +1,3 @@ from . import payment_provider from . import payment_transaction -from . import account_payment \ No newline at end of file +from . import account_payment diff --git a/payment_multic_ux/models/account_payment.py b/payment_multic_ux/models/account_payment.py index e90c03af..5dd40e54 100644 --- a/payment_multic_ux/models/account_payment.py +++ b/payment_multic_ux/models/account_payment.py @@ -1,17 +1,16 @@ -from odoo import models, api +from odoo import api, models class AccountPayment(models.Model): - _inherit = 'account.payment' - + _inherit = "account.payment" @api.model_create_multi def create(self, val_list): - force_company = self.env.context.get('force_company_id') + force_company = self.env.context.get("force_company_id") if force_company: if isinstance(val_list, list): for vals in val_list: - vals['company_id'] = force_company + vals["company_id"] = force_company else: - val_list['company_id'] = force_company + val_list["company_id"] = force_company return super().create(val_list) diff --git a/payment_multic_ux/models/payment_provider.py b/payment_multic_ux/models/payment_provider.py index e10ac397..272693c8 100644 --- a/payment_multic_ux/models/payment_provider.py +++ b/payment_multic_ux/models/payment_provider.py @@ -4,10 +4,8 @@ class PaymentProvider(models.Model): - _inherit = 'payment.provider' + _inherit = "payment.provider" journal_id = fields.Many2one( - compute=False, - inverse='_inverse_journal_id', - domain="[('type', 'in', ('bank', 'cash'))]", - check_company=False) + compute=False, inverse="_inverse_journal_id", domain="[('type', 'in', ('bank', 'cash'))]", check_company=False + ) diff --git a/payment_multic_ux/models/payment_transaction.py b/payment_multic_ux/models/payment_transaction.py index e32c161b..e04ec12e 100644 --- a/payment_multic_ux/models/payment_transaction.py +++ b/payment_multic_ux/models/payment_transaction.py @@ -2,8 +2,10 @@ class PaymentTransaction(models.Model): - _inherit = 'payment.transaction' + _inherit = "payment.transaction" def _create_payment(self, **extra_create_values): # Add force_company to catch later in the account.payment creation. - return super(PaymentTransaction, self.with_context(force_company_id=self.provider_id.journal_id.company_id.id))._create_payment(**extra_create_values) + return super( + PaymentTransaction, self.with_context(force_company_id=self.provider_id.journal_id.company_id.id) + )._create_payment(**extra_create_values) diff --git a/website_multicompany/__manifest__.py b/website_multicompany/__manifest__.py index 8f9f3ab2..ae6db08d 100644 --- a/website_multicompany/__manifest__.py +++ b/website_multicompany/__manifest__.py @@ -18,16 +18,16 @@ # ############################################################################## { - 'name': 'Website Multicompany', - 'version': "18.0.1.0.0", - 'author': 'ADHOC SA', - 'website': 'www.adhoc.com.ar', - 'license': 'AGPL-3', - 'depends': [ - 'website', + "name": "Website Multicompany", + "version": "18.0.1.0.0", + "author": "ADHOC SA", + "website": "www.adhoc.com.ar", + "license": "AGPL-3", + "depends": [ + "website", ], - 'data': [], - 'demo': [], - 'installable': True, - 'auto_install': False, + "data": [], + "demo": [], + "installable": True, + "auto_install": False, } diff --git a/website_multicompany/models/ir_http.py b/website_multicompany/models/ir_http.py index 4680c80d..ebcc2960 100644 --- a/website_multicompany/models/ir_http.py +++ b/website_multicompany/models/ir_http.py @@ -8,18 +8,18 @@ class Http(models.AbstractModel): - _inherit = 'ir.http' + _inherit = "ir.http" @classmethod def _frontend_pre_dispatch(cls): super()._frontend_pre_dispatch() user = request.env.user - website = request.env['website'].get_current_website() + website = request.env["website"].get_current_website() # Si el usuario no es el usuario publico las companias allowed son las companias del usuario # Esto lo hago para evitar que los usuarios vean todos los registros (sale.order, account.move) # en le portal (las alowed_companys se transforman el las companias que filtro en ir.rules) - if user.id != website._get_cached('user_id'): + if user.id != website._get_cached("user_id"): users_company_ids = website._get_cached_companies() request.update_context( allowed_company_ids=users_company_ids, diff --git a/website_multicompany/models/website.py b/website_multicompany/models/website.py index 15413d8d..8fca3167 100644 --- a/website_multicompany/models/website.py +++ b/website_multicompany/models/website.py @@ -7,9 +7,8 @@ class Website(models.Model): + _inherit = "website" - _inherit = 'website' - - @tools.ormcache('self.env.uid') + @tools.ormcache("self.env.uid") def _get_cached_companies(self): return self.env.user.company_ids.ids diff --git a/website_sale_multic_ux/__manifest__.py b/website_sale_multic_ux/__manifest__.py index b7e71e9b..614148ad 100644 --- a/website_sale_multic_ux/__manifest__.py +++ b/website_sale_multic_ux/__manifest__.py @@ -18,17 +18,17 @@ # ############################################################################## { - 'name': 'Website Sale Multicompany Usability', - 'version': "18.0.1.0.0", - 'author': 'ADHOC SA', - 'website': 'www.adhoc.com.ar', - 'license': 'AGPL-3', - 'depends': [ - 'website_sale', - 'payment_multic_ux', + "name": "Website Sale Multicompany Usability", + "version": "18.0.1.0.0", + "author": "ADHOC SA", + "website": "www.adhoc.com.ar", + "license": "AGPL-3", + "depends": [ + "website_sale", + "payment_multic_ux", ], - 'data': [], - 'demo': [], - 'installable': True, - 'auto_install': False, + "data": [], + "demo": [], + "installable": True, + "auto_install": False, } diff --git a/website_sale_multic_ux/controllers/main.py b/website_sale_multic_ux/controllers/main.py index 299bd489..6e75dceb 100644 --- a/website_sale_multic_ux/controllers/main.py +++ b/website_sale_multic_ux/controllers/main.py @@ -1,12 +1,8 @@ from odoo.addons.website_sale.controllers.main import WebsiteSale - class WebsiteSale(WebsiteSale): - - def _complete_address_values( - self, address_values, address_type, use_delivery_as_billing, order_sudo - ): + def _complete_address_values(self, address_values, address_type, use_delivery_as_billing, order_sudo): super()._complete_address_values(address_values, address_type, use_delivery_as_billing, order_sudo) - if not address_values['user_id']: - address_values['company_id'] = False + if not address_values["user_id"]: + address_values["company_id"] = False diff --git a/website_sale_multicompany/__manifest__.py b/website_sale_multicompany/__manifest__.py index a315a5ba..5c73648b 100644 --- a/website_sale_multicompany/__manifest__.py +++ b/website_sale_multicompany/__manifest__.py @@ -18,17 +18,17 @@ # ############################################################################## { - 'name': 'Website Sale multicompany', - 'version': "18.0.1.0.0", - 'author': 'ADHOC SA', - 'website': 'www.adhoc.com.ar', - 'license': 'AGPL-3', - 'depends': [ - 'website_sale', - 'website_multicompany', + "name": "Website Sale multicompany", + "version": "18.0.1.0.0", + "author": "ADHOC SA", + "website": "www.adhoc.com.ar", + "license": "AGPL-3", + "depends": [ + "website_sale", + "website_multicompany", ], - 'data': [], - 'demo': [], - 'installable': True, - 'auto_install': False, + "data": [], + "demo": [], + "installable": True, + "auto_install": False, } diff --git a/website_sale_multicompany/controllers/portal.py b/website_sale_multicompany/controllers/portal.py index c55ed6e7..49848102 100644 --- a/website_sale_multicompany/controllers/portal.py +++ b/website_sale_multicompany/controllers/portal.py @@ -1,26 +1,23 @@ - -import urllib.parse - -from odoo import _, http -from odoo.http import request - +from odoo import http from odoo.addons.payment import utils as payment_utils -from odoo.addons.payment.controllers.post_processing import PaymentPostProcessing from odoo.addons.payment.controllers import portal from odoo.exceptions import AccessError, MissingError +from odoo.http import request -class PaymentPortal(portal.PaymentPortal): +class PaymentPortal(portal.PaymentPortal): @http.route() def payment_method(self, **kwargs): - """ Remplazo el metodo del controlador de odoo porque la compañia de esta url es siempre la + """Remplazo el metodo del controlador de odoo porque la compañia de esta url es siempre la del website y necesitamos que sea la del usuario o la de la subscricion que vamos a pagar. """ partner_sudo = request.env.user.partner_id # env.user is always sudoed - if 'sale_order_id' in kwargs and 'access_token' in kwargs: + if "sale_order_id" in kwargs and "access_token" in kwargs: try: - order_sudo = self._document_check_access('sale.order', int(kwargs.get('sale_order_id')), access_token=kwargs.get('access_token')) + order_sudo = self._document_check_access( + "sale.order", int(kwargs.get("sale_order_id")), access_token=kwargs.get("access_token") + ) company_id = order_sudo.company_id except (AccessError, MissingError): company_id = request.env.user.company_id @@ -29,46 +26,54 @@ def payment_method(self, **kwargs): company_id = request.env.user.company_id availability_report = {} # Select all the payment methods and tokens that match the payment context. - providers_sudo = request.env['payment.provider'].sudo()._get_compatible_providers( - company_id.id, - partner_sudo.id, - 0., # There is no amount to pay with validation transactions. - force_tokenization=True, - is_validation=True, - report=availability_report, - **kwargs, + providers_sudo = ( + request.env["payment.provider"] + .sudo() + ._get_compatible_providers( + company_id.id, + partner_sudo.id, + 0.0, # There is no amount to pay with validation transactions. + force_tokenization=True, + is_validation=True, + report=availability_report, + **kwargs, + ) ) # In sudo mode to read the fields of providers and partner (if logged out). - payment_methods_sudo = request.env['payment.method'].sudo()._get_compatible_payment_methods( - providers_sudo.ids, - partner_sudo.id, - force_tokenization=True, - report=availability_report, + payment_methods_sudo = ( + request.env["payment.method"] + .sudo() + ._get_compatible_payment_methods( + providers_sudo.ids, + partner_sudo.id, + force_tokenization=True, + report=availability_report, + ) ) # In sudo mode to read the fields of providers. - tokens_sudo = request.env['payment.token'].sudo()._get_available_tokens( - None, partner_sudo.id, is_validation=True + tokens_sudo = ( + request.env["payment.token"].sudo()._get_available_tokens(None, partner_sudo.id, is_validation=True) ) # In sudo mode to read the commercial partner's and providers' fields. access_token = payment_utils.generate_access_token(partner_sudo.id, None, None) payment_form_values = { - 'mode': 'validation', - 'allow_token_selection': False, - 'allow_token_deletion': True, + "mode": "validation", + "allow_token_selection": False, + "allow_token_deletion": True, } payment_context = { - 'reference_prefix': payment_utils.singularize_reference_prefix(prefix='V'), - 'partner_id': partner_sudo.id, - 'providers_sudo': providers_sudo, - 'payment_methods_sudo': payment_methods_sudo, - 'tokens_sudo': tokens_sudo, - 'availability_report': availability_report, - 'transaction_route': '/payment/transaction', - 'landing_route': '/my/payment_method', - 'access_token': access_token, + "reference_prefix": payment_utils.singularize_reference_prefix(prefix="V"), + "partner_id": partner_sudo.id, + "providers_sudo": providers_sudo, + "payment_methods_sudo": payment_methods_sudo, + "tokens_sudo": tokens_sudo, + "availability_report": availability_report, + "transaction_route": "/payment/transaction", + "landing_route": "/my/payment_method", + "access_token": access_token, } rendering_context = { **payment_form_values, **payment_context, **self._get_extra_payment_form_values(**kwargs), } - return request.render('payment.payment_methods', rendering_context) + return request.render("payment.payment_methods", rendering_context) diff --git a/website_sale_multicompany/models/sale_order.py b/website_sale_multicompany/models/sale_order.py index 4bb30b7f..3c3c6ffb 100644 --- a/website_sale_multicompany/models/sale_order.py +++ b/website_sale_multicompany/models/sale_order.py @@ -3,15 +3,14 @@ # directory ############################################################################## -from odoo import models, fields +from odoo import models class SaleOrder(models.Model): - - _inherit = 'sale.order' + _inherit = "sale.order" def _sale_get_order_company_fix(self): vals = {} if self.company_id != self.env.user.company_id: - vals['company_id'] = self.env.user.company_id.id + vals["company_id"] = self.env.user.company_id.id return vals diff --git a/website_sale_multicompany/models/website.py b/website_sale_multicompany/models/website.py index 7def030d..44b723f0 100644 --- a/website_sale_multicompany/models/website.py +++ b/website_sale_multicompany/models/website.py @@ -3,14 +3,11 @@ # directory ############################################################################## -import logging -from odoo import models, tools -from odoo.http import request +from odoo import models class Website(models.Model): - - _inherit = 'website' + _inherit = "website" def sale_get_order(self, force_create=False): sale_order_sudo = super().sale_get_order(force_create) diff --git a/website_sale_stock_multicompany/__manifest__.py b/website_sale_stock_multicompany/__manifest__.py index ce045bbb..ab75a6b5 100644 --- a/website_sale_stock_multicompany/__manifest__.py +++ b/website_sale_stock_multicompany/__manifest__.py @@ -18,17 +18,17 @@ # ############################################################################## { - 'name': 'Website Sale stock multicompany', - 'version': "18.0.1.0.0", - 'author': 'ADHOC SA', - 'website': 'www.adhoc.com.ar', - 'license': 'AGPL-3', - 'depends': [ - 'website_sale_stock', - 'website_sale_multicompany', + "name": "Website Sale stock multicompany", + "version": "18.0.1.0.0", + "author": "ADHOC SA", + "website": "www.adhoc.com.ar", + "license": "AGPL-3", + "depends": [ + "website_sale_stock", + "website_sale_multicompany", ], - 'data': [], - 'demo': [], - 'installable': True, - 'auto_install': True, + "data": [], + "demo": [], + "installable": True, + "auto_install": True, } diff --git a/website_sale_stock_multicompany/models/sale_order.py b/website_sale_stock_multicompany/models/sale_order.py index a3a90401..9579fffe 100644 --- a/website_sale_stock_multicompany/models/sale_order.py +++ b/website_sale_stock_multicompany/models/sale_order.py @@ -7,23 +7,24 @@ class SaleOrder(models.Model): - - _inherit = 'sale.order' + _inherit = "sale.order" def _sale_get_order_company_fix(self): vals = super()._sale_get_order_company_fix() if self.warehouse_id.company_id != self.env.user.company_id: - vals['warehouse_id'] = self.website_id.with_context(company_fix=self.env.user.company_id.id - )._get_warehouse_available() + vals["warehouse_id"] = self.website_id.with_context( + company_fix=self.env.user.company_id.id + )._get_warehouse_available() return vals def _get_warehouse_available(self): self.ensure_one() warehouse = super()._get_warehouse_available() if warehouse: - warehouse_id = self.env['stock.warehouse'].browse(warehouse) + warehouse_id = self.env["stock.warehouse"].browse(warehouse) if warehouse_id.company_id != self.company_id: - warehouse = self.website_id.with_context(company_fix=self.env.user.company_id.id - )._get_warehouse_available() + warehouse = self.website_id.with_context( + company_fix=self.env.user.company_id.id + )._get_warehouse_available() return warehouse diff --git a/website_sale_stock_multicompany/models/website.py b/website_sale_stock_multicompany/models/website.py index 3a1c771e..fcff939a 100644 --- a/website_sale_stock_multicompany/models/website.py +++ b/website_sale_stock_multicompany/models/website.py @@ -7,14 +7,13 @@ class Website(models.Model): - - _inherit = 'website' + _inherit = "website" def _get_warehouse_available(self): - if self._context.get('company_fix'): - company = self._context.get('company_fix') + if self._context.get("company_fix"): + company = self._context.get("company_fix") return ( - self.env['ir.default'].sudo()._get('sale.order', 'warehouse_id', company_id=company) or - self.env['stock.warehouse'].sudo().search([('company_id', '=', company)], limit=1).id - ) + self.env["ir.default"].sudo()._get("sale.order", "warehouse_id", company_id=company) + or self.env["stock.warehouse"].sudo().search([("company_id", "=", company)], limit=1).id + ) return super()._get_warehouse_available()