-
-
Notifications
You must be signed in to change notification settings - Fork 290
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] product_tax_multicompany_default: Extend ignored_company_ids co…
…ntext functionality
- Loading branch information
1 parent
2a40131
commit d04b566
Showing
2 changed files
with
64 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
# Copyright 2017 Carlos Dauden - Tecnativa <[email protected]> | ||
# Copyright 2018 Vicent Cubells - Tecnativa <[email protected]> | ||
# Copyright 2023 Eduardo de Miguel - Moduon <[email protected]> | ||
# Copyright 2025 Sergio Bustamante - FactorLibre <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from typing import List | ||
|
@@ -101,6 +102,8 @@ def _delete_product_taxes( | |
|
||
def set_multicompany_taxes(self): | ||
self.ensure_one() | ||
ignored_company_ids = self.env.context.get("ignored_company_ids", []) | ||
ignored_taxes_id = self._get_ignored_taxes_id(ignored_company_ids) or [] | ||
user_company = self.env.company | ||
customer_tax = self.taxes_id | ||
customer_tax_ids = customer_tax.ids | ||
|
@@ -119,8 +122,8 @@ def set_multicompany_taxes(self): | |
) | ||
# Clean taxes from other companies (cannot replace it with sudo) | ||
self._delete_product_taxes( | ||
excl_customer_tax_ids=customer_tax_ids, | ||
excl_supplier_tax_ids=supplier_tax_ids, | ||
excl_customer_tax_ids=customer_tax_ids + ignored_taxes_id, | ||
excl_supplier_tax_ids=supplier_tax_ids + ignored_taxes_id, | ||
) | ||
# Use list() to copy list | ||
match_customer_tax_ids = ( | ||
|
@@ -133,7 +136,8 @@ def set_multicompany_taxes(self): | |
if default_supplier_tax_ids != supplier_tax_ids | ||
else None | ||
) | ||
for company in obj.env["res.company"].search([("id", "!=", user_company.id)]): | ||
company_ids = ignored_company_ids + [user_company.id] | ||
for company in obj.env["res.company"].search([("id", "not in", company_ids)]): | ||
customer_tax_ids.extend( | ||
obj.taxes_by_company( | ||
"account_sale_tax_id", company, match_customer_tax_ids | ||
|
@@ -146,8 +150,8 @@ def set_multicompany_taxes(self): | |
) | ||
self.write( | ||
{ | ||
"taxes_id": [(6, 0, customer_tax_ids)], | ||
"supplier_taxes_id": [(6, 0, supplier_tax_ids)], | ||
"taxes_id": [[4, tax] for tax in customer_tax_ids], | ||
"supplier_taxes_id": [[4, tax] for tax in supplier_tax_ids], | ||
} | ||
) | ||
|
||
|
@@ -158,6 +162,17 @@ def create(self, vals_list): | |
product.set_multicompany_taxes() | ||
return new_products | ||
|
||
def _get_ignored_taxes_id(self, ignored_company_ids): | ||
ignored_taxes_ids = False | ||
if ignored_company_ids: | ||
ignored_taxes_ids = ( | ||
self.env["account.tax"] | ||
.sudo() | ||
.search([("company_id", "in", ignored_company_ids)]) | ||
.ids | ||
) | ||
return ignored_taxes_ids | ||
|
||
|
||
class ProductProduct(models.Model): | ||
_inherit = "product.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