-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] g_p_change_sale_move: Aggregate policy
Add a new parameter on res.company to choose how move.line are aggregated when closing a pos.session. Two options can be selected: 1. "Group by account and tax", it means that: - product move.line are aggregated by account and by taxes. - tax move.line are aggregated by tax. - only one counter part move.line are written for the whole pos.session 2. "Group by account, tax and partner", it means that: - product move.line are aggregated by account, by taxes and by partner. - tax move.line are aggregated by tax and by partner. - counter part move.line are aggregated by partner. This is a first attempt. Readme should be changed later when these changes will be validated.
- Loading branch information
Showing
8 changed files
with
394 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
from . import res_company | ||
from . import pos_order |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
# Copyright (C) 2017 - Today: GRAP (http://www.grap.coop) | ||
# Copyright (C) 2021 - Today: Coop IT Easy (http://coopiteasy.be) | ||
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain) | ||
# @author: Rémy TAYMANS ([email protected]) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from odoo import api, models | ||
|
@@ -8,48 +10,57 @@ | |
class PosOrder(models.Model): | ||
_inherit = "pos.order" | ||
|
||
def _get_group_by_keys(self): | ||
"""Return keys used to aggregate the account moves.""" | ||
company = self[0].session_id.config_id.company_id | ||
pos_sale_move_policy = company.pos_sale_move_policy | ||
return {"partner": "partner" in pos_sale_move_policy} | ||
|
||
# Overwrite this Odoo function. | ||
# Remove partner_id product_id and name from the keys. | ||
@api.model | ||
def _get_account_move_line_group_data_type_key( | ||
self, data_type, values, options=False | ||
): | ||
options = options or {} | ||
groupby = self._get_group_by_keys() | ||
if data_type == "product": | ||
return ( | ||
"product", | ||
# Remove partner_id | ||
False, | ||
# remove product_id (1) and name (3) | ||
(False, tuple(values["tax_ids"][0][2]), False), | ||
values["analytic_account_id"], | ||
values["debit"] > 0, | ||
values.get("currency_id"), | ||
# Add new key "account_id" | ||
values["account_id"], | ||
) | ||
tax_ids = values["tax_ids"][0][2] | ||
|
||
product_key = ["product"] | ||
if groupby["partner"]: | ||
product_key.append(values["partner_id"]) | ||
# remove product_id (0) and name (2), keep tax (1) | ||
product_key.append((False, tuple(tax_ids), False)) | ||
product_key.append(values["analytic_account_id"]) | ||
product_key.append(values["debit"] > 0) | ||
product_key.append(values.get("currency_id")) | ||
# Add new key "account_id" | ||
product_key.append(values["account_id"]) | ||
|
||
return tuple(product_key) | ||
elif data_type == "tax": | ||
order_id = values.pop("order_id", False) | ||
tax_key = ( | ||
"tax", | ||
# remove partner_id | ||
False, | ||
values["tax_line_id"], | ||
values["debit"] > 0, | ||
values.get("currency_id"), | ||
) | ||
|
||
tax_key = ["tax"] | ||
if groupby["partner"]: | ||
tax_key.append(values["partner_id"]) | ||
tax_key.append(values["tax_line_id"]) | ||
tax_key.append(values["debit"] > 0) | ||
if options.get("rounding_method") == "round_globally": | ||
tax_key = ("tax", values["tax_line_id"], order_id) | ||
return tax_key | ||
|
||
return tuple(tax_key) | ||
elif data_type == "counter_part": | ||
return ( | ||
"counter_part", | ||
# remove partner_id | ||
False, | ||
values["account_id"], | ||
values["debit"] > 0, | ||
values.get("currency_id"), | ||
) | ||
counter_part_key = ["counter_part"] | ||
|
||
if groupby["partner"]: | ||
counter_part_key.append(values["partner_id"] or 0) | ||
counter_part_key.append(values["account_id"]) | ||
counter_part_key.append(values["debit"] > 0) | ||
counter_part_key.append(values.get("currency_id")) | ||
|
||
return tuple(counter_part_key) | ||
return False | ||
|
||
# Overload this Odoo function. | ||
|
@@ -58,9 +69,11 @@ def _prepare_account_move_and_lines(self, session=None, move=None): | |
res = super()._prepare_account_move_and_lines(session=session, move=move) | ||
AccountAccount = self.env["account.account"] | ||
grouped_data = res.get("grouped_data") | ||
groupby = self._get_group_by_keys() | ||
for k, values in grouped_data.items(): | ||
for value in values: | ||
value["partner_id"] = False | ||
if not groupby["partner"]: | ||
value["partner_id"] = False | ||
value["product_id"] = False | ||
value["quantity"] = False | ||
if k[0] == "product": | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Copyright (C) 2021 - Today: Coop IT Easy (http://coopiteasy.be) | ||
# @author: Rémy TAYMANS ([email protected]) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from odoo import fields, models | ||
|
||
|
||
class ResCompany(models.Model): | ||
_inherit = "res.company" | ||
|
||
pos_sale_move_policy = fields.Selection( | ||
selection=[ | ||
("groupby_account_tax", "Group by Account and tax"), | ||
("groupby_account_tax_partner", "Group by account, tax and partner"), | ||
], | ||
default="groupby_account_tax", | ||
help="Select how PoS account moves should be aggregated", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<odoo> | ||
<record id="view_company_form" model="ir.ui.view"> | ||
<field name="name">res.company.form</field> | ||
<field name="model">res.company</field> | ||
<field name="inherit_id" ref="base.view_company_form"/> | ||
<field name="arch" type="xml"> | ||
<field name="currency_id" position="after"> | ||
<field name="pos_sale_move_policy"/> | ||
</field> | ||
</field> | ||
</record> | ||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.