From 7c1cdcbf8152ada62694418a85bab629aceeb40f Mon Sep 17 00:00:00 2001 From: Antoni Marroig Campomar Date: Tue, 30 Apr 2024 10:02:11 +0200 Subject: [PATCH] [MIG] pos_analytic_by_config: Migration to 17.0 --- pos_analytic_by_config/README.rst | 4 ++ pos_analytic_by_config/__manifest__.py | 2 +- .../migrations/16.0.1.0.0/post-migration.py | 66 ------------------- .../models/analytic_distribution_model.py | 3 +- pos_analytic_by_config/readme/CONTRIBUTORS.md | 2 + .../static/description/index.html | 15 +++-- .../tests/test_pos_analytic_by_config.py | 4 ++ 7 files changed, 24 insertions(+), 72 deletions(-) delete mode 100644 pos_analytic_by_config/migrations/16.0.1.0.0/post-migration.py diff --git a/pos_analytic_by_config/README.rst b/pos_analytic_by_config/README.rst index 04ea6d41d3..c5cc054428 100644 --- a/pos_analytic_by_config/README.rst +++ b/pos_analytic_by_config/README.rst @@ -95,6 +95,10 @@ Contributors - David Vidal +- `APSL-Nagarro `__ + + - Antoni Marroig + Maintainers ----------- diff --git a/pos_analytic_by_config/__manifest__.py b/pos_analytic_by_config/__manifest__.py index 8c6be3a1c2..4649d0d37b 100644 --- a/pos_analytic_by_config/__manifest__.py +++ b/pos_analytic_by_config/__manifest__.py @@ -7,7 +7,7 @@ "author": "ACSONE SA/NV, Tecnativa, Odoo Community Association (OCA)", "website": "https://github.com/OCA/account-analytic", "category": "Point Of Sale, Accounting", - "version": "16.0.1.0.0", + "version": "17.0.1.0.0", "license": "AGPL-3", "depends": ["point_of_sale"], "data": [ diff --git a/pos_analytic_by_config/migrations/16.0.1.0.0/post-migration.py b/pos_analytic_by_config/migrations/16.0.1.0.0/post-migration.py deleted file mode 100644 index b97d43872e..0000000000 --- a/pos_analytic_by_config/migrations/16.0.1.0.0/post-migration.py +++ /dev/null @@ -1,66 +0,0 @@ -# Copyright 2024 Tecnativa - David Vidal -# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). -from openupgradelib import openupgrade - - -@openupgrade.migrate() -def migrate(env, version): - """ - For every company: - - Check if there are analytic accounts configured in that company's pos configs - - If so, create a new analytic plan (Stores) - - Assign that analytic plan to the pos configs analytic accounts - - Create a miscellaneous applicability rule that is mandatory - - Create an analytic distribution model for each pos_config / analytic account - """ - env.cr.execute( - """ - SELECT id, account_analytic_id FROM pos_config - WHERE account_analytic_id IS NOT NULL - """ - ) - pos_configs_dict = { - env["pos.config"].browse(id): env["analytic.account"].browse(aa_id) - for id, aa_id, *_ in env.cr.fetchall() - } - pos_configs = env["pos.config"].browse([pc.id for pc in pos_configs_dict.keys()]) - for company in pos_configs.company_id: - company_configs = pos_configs.filtered( - lambda x, company=company: x.company_id == company - ) - default_account_revenue = env["account.account"].search( - [ - ("company_id", "=", company.id), - ("account_type", "=", "income"), - ( - "id", - "!=", - company.account_journal_early_pay_discount_gain_account_id.id, - ), - ], - limit=1, - ) - analytic_plan = env["account.analytic.plan"].create( - { - "name": "Stores", - "default_applicability": "optional", - "company_id": company.id, - } - ) - env["account.analytic.applicability"].create( - { - "business_domain": "general", - "analytic_plan_id": analytic_plan.id, - "applicability": "mandatory", - } - ) - for config in company_configs: - analytic_account = pos_configs_dict[config] - analytic_account.analytic_plan_id = analytic_plan.id - env["account.analytic.distribution.model"].create( - { - "account_prefix": default_account_revenue.code[:3], - "pos_config_id": config.id, - "analytic_distribution": {analytic_account.id: 100}, - } - ) diff --git a/pos_analytic_by_config/models/analytic_distribution_model.py b/pos_analytic_by_config/models/analytic_distribution_model.py index 931139556e..e39290cfa6 100644 --- a/pos_analytic_by_config/models/analytic_distribution_model.py +++ b/pos_analytic_by_config/models/analytic_distribution_model.py @@ -12,7 +12,8 @@ class AccountAnalyticDistributionModel(models.Model): help="Select a Point of Sale for which the analytic distribution will be used", ) - def _get_distribution(self, vals): + def _get_distribution(self, new_vals): + vals = new_vals.copy() pos_config_id = self.env.context.get("pos_config_id") if pos_config_id: vals["pos_config_id"] = pos_config_id diff --git a/pos_analytic_by_config/readme/CONTRIBUTORS.md b/pos_analytic_by_config/readme/CONTRIBUTORS.md index 6ca1e08205..463601d1e1 100644 --- a/pos_analytic_by_config/readme/CONTRIBUTORS.md +++ b/pos_analytic_by_config/readme/CONTRIBUTORS.md @@ -4,3 +4,5 @@ - Xavier Bouquiaux \<\> - [Tecnativa](https://www.tecnativa.com) - David Vidal +- [APSL-Nagarro](https://www.apsl.tech) + - Antoni Marroig \<\> diff --git a/pos_analytic_by_config/static/description/index.html b/pos_analytic_by_config/static/description/index.html index c2e0dcdc51..2756ddf85c 100644 --- a/pos_analytic_by_config/static/description/index.html +++ b/pos_analytic_by_config/static/description/index.html @@ -9,10 +9,11 @@ /* :Author: David Goodger (goodger@python.org) -:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $ +:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $ :Copyright: This stylesheet has been placed in the public domain. Default cascading style sheet for the HTML output of Docutils. +Despite the name, some widely supported CSS2 features are used. See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to customize this style sheet. @@ -275,7 +276,7 @@ margin-left: 2em ; margin-right: 2em } -pre.code .ln { color: grey; } /* line numbers */ +pre.code .ln { color: gray; } /* line numbers */ pre.code, code { background-color: #eeeeee } pre.code .comment, code .comment { color: #5C6576 } pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold } @@ -301,7 +302,7 @@ span.pre { white-space: pre } -span.problematic { +span.problematic, pre.problematic { color: red } span.section-subtitle { @@ -444,12 +445,18 @@

Contributors

  • David Vidal
  • +
  • APSL-Nagarro +
  • Maintainers

    This module is maintained by the OCA.

    -Odoo Community Association + +Odoo Community Association +

    OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use.

    diff --git a/pos_analytic_by_config/tests/test_pos_analytic_by_config.py b/pos_analytic_by_config/tests/test_pos_analytic_by_config.py index 51f4cc739b..339513f858 100644 --- a/pos_analytic_by_config/tests/test_pos_analytic_by_config.py +++ b/pos_analytic_by_config/tests/test_pos_analytic_by_config.py @@ -38,6 +38,10 @@ def setUpClass(cls): } ) cls.config = cls.basic_config + # Set the cash payment method to False for split transactions + cls.config.payment_method_ids.filtered_domain( + [("type", "=", "cash")] + ).split_transactions = False cls.session = cls.open_new_session(cls) def _create_order(self):