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] pos_analytic_by_config: Avoid prefixing #734

Open
wants to merge 1 commit into
base: 16.0
Choose a base branch
from
Open
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
14 changes: 1 addition & 13 deletions pos_analytic_by_config/migrations/16.0.1.0.0/post-migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,6 @@ def migrate(env, version):
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: 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",
Expand All @@ -57,7 +45,7 @@ def migrate(env, version):
analytic_account.plan_id = analytic_plan.id
env["account.analytic.distribution.model"].create(
{
"account_prefix": default_account_revenue.code[:3],
"account_prefix": "",
"pos_config_id": config.id,
"analytic_distribution": {analytic_account.id: 100},
"company_id": company.id,
Expand Down
1 change: 1 addition & 0 deletions pos_analytic_by_config/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from . import analytic_distribution_model
from . import pos_order
from . import pos_session
from . import account_move_line
18 changes: 18 additions & 0 deletions pos_analytic_by_config/models/account_move_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright 2025 Tecnativa - David Vidal
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import api, models


class AccountMoveLine(models.Model):
_inherit = "account.move.line"

@api.model_create_multi
def create(self, vals_list):
"""We need to receive this key from the vals as the create call is encampsulated
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"""We need to receive this key from the vals as the create call is encampsulated
"""We need to receive this key from the vals as the create call is encapsulated

inside the _get_sale_vals method of the pos.session model."""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not explaining how and where pos_config_id context is used. docstring also puts the trailing """ in a new line according PEP257.

config_id = vals_list and vals_list[0].get("pos_config_id")
if config_id:
for vals in vals_list:
vals.pop("pos_config_id", None)
self = self.with_context(pos_config_id=config_id)
return super().create(vals_list)
21 changes: 8 additions & 13 deletions pos_analytic_by_config/models/pos_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,11 @@
class PosSession(models.Model):
_inherit = "pos.session"

def _validate_session(
self,
balancing_account=False,
amount_to_balance=0,
bank_payment_method_diffs=None,
):
return super(
PosSession, self.with_context(pos_config_id=self.config_id.id)
)._validate_session(
balancing_account=balancing_account,
amount_to_balance=amount_to_balance,
bank_payment_method_diffs=bank_payment_method_diffs,
)
def _get_sale_vals(self, key, amount, amount_converted):
"""We can't use the context as the creation of the sale move lines is
encapsulated inside the _create_non_reconciliable_move_lines method and that
one creates another kind of move lines as well. So we're passing the session
as a vals key and later we pop it from the dictionary."""
vals = super()._get_sale_vals(key, amount, amount_converted)
vals["pos_config_id"] = self.config_id.id
return vals
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def setUpClass(cls):
)
cls.env["account.analytic.distribution.model"].create(
{
"account_prefix": cls.sales_account.code,
"account_prefix": "",
"pos_config_id": cls.basic_config.id,
"analytic_distribution": {cls.analytic_account.id: 100},
}
Expand Down
Loading