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

[17.0][FIX] sale_blanket_order: filter default taxes by company for all users #3288

Open
wants to merge 1 commit into
base: 17.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
24 changes: 10 additions & 14 deletions sale_blanket_order/models/blanket_orders.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright 2018 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import SUPERUSER_ID, _, api, fields, models
from odoo import _, api, fields, models
from odoo.exceptions import UserError
from odoo.tools import float_is_zero
from odoo.tools.misc import format_date
Expand Down Expand Up @@ -110,7 +110,9 @@ def _compute_amount_all(self):
sale_count = fields.Integer(compute="_compute_sale_count")

fiscal_position_id = fields.Many2one(
"account.fiscal.position", string="Fiscal Position"
"account.fiscal.position",
string="Fiscal Position",
check_company=True,
)

amount_untaxed = fields.Monetary(
Expand Down Expand Up @@ -419,9 +421,9 @@ def _compute_amount(self):
product_uom = fields.Many2one("uom.uom", string="Unit of Measure")
price_unit = fields.Float(string="Price", digits="Product Price")
taxes_id = fields.Many2many(
"account.tax",
string="Taxes",
domain=["|", ("active", "=", False), ("active", "=", True)],
comodel_name="account.tax",
context={"active_test": False},
check_company=True,
)
date_schedule = fields.Date(string="Scheduled Date")
original_uom_qty = fields.Float(
Expand Down Expand Up @@ -616,15 +618,9 @@ def onchange_product(self):
self.name = name

fpos = self.order_id.fiscal_position_id
if self.env.uid == SUPERUSER_ID:
company_id = self.env.company.id
self.taxes_id = fpos.map_tax(
self.product_id.taxes_id.filtered(
lambda r: r.company_id.id == company_id
)
)
else:
self.taxes_id = fpos.map_tax(self.product_id.taxes_id)
self.taxes_id = fpos.map_tax(
self.product_id.taxes_id._filter_taxes_by_company(self.company_id)
)

@api.depends(
"sale_lines.order_id.state",
Expand Down
50 changes: 50 additions & 0 deletions sale_blanket_order/tests/test_blanket_orders.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,54 @@ def setUpClass(cls):
{"name": "Test Pricelist", "currency_id": cls.env.ref("base.USD").id}
)

# Taxes
company_partner = cls.env["res.partner"].create(
{
"name": __name__,
"country_id": cls.env.company.country_id.id,
}
)
company2 = cls.env["res.company"].create(
{
"name": __name__,
"partner_id": company_partner.id,
},
)
cls.env.user.company_ids += company2
cls.env = cls.env(
context=dict(
cls.env.context, allowed_company_ids=[cls.env.company.id, company2.id]
)
)
tax_group1 = cls.env["account.tax.group"].create(
{
"name": cls.env.company.name,
"company_id": cls.env.company.id,
}
)
tax_group2 = cls.env["account.tax.group"].create(
{
"name": company2.name,
"company_id": company2.id,
}
)
cls.tax1 = cls.env["account.tax"].create(
{
"name": cls.env.company.name,
"company_id": cls.env.company.id,
"amount": 10,
"tax_group_id": tax_group1.id,
}
)
cls.tax2 = cls.env["account.tax"].create(
{
"name": company2.name,
"company_id": company2.id,
"amount": 20,
"tax_group_id": tax_group2.id,
}
)

# UoM
cls.categ_unit = cls.env.ref("uom.product_uom_categ_unit")
cls.uom_dozen = cls.env["uom.uom"].create(
Expand Down Expand Up @@ -48,6 +96,7 @@ def setUpClass(cls):
"type": "consu",
"uom_id": cls.env.ref("uom.product_uom_unit").id,
"default_code": "PROD_DEL01",
"taxes_id": [fields.Command.set([cls.tax1.id, cls.tax2.id])],
}
)
cls.product2 = cls.env["product.product"].create(
Expand Down Expand Up @@ -97,6 +146,7 @@ def test_01_create_blanket_order(self):
blanket_order.sudo().onchange_partner_id()
blanket_order.pricelist_id.discount_policy = "without_discount"
blanket_order.line_ids[0].sudo().onchange_product()
self.assertEqual(blanket_order.line_ids[0].taxes_id, self.tax1)
blanket_order.pricelist_id.discount_policy = "with_discount"
blanket_order.line_ids[0].sudo().onchange_product()
blanket_order.line_ids[0].sudo()._get_display_price()
Expand Down
4 changes: 2 additions & 2 deletions sale_blanket_order/views/sale_blanket_order_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@
<field
name="taxes_id"
widget="many2many_tags"
domain="[('type_tax_use','=','sale')]"
context="{'default_type_tax_use': 'sale'}"
domain="[('type_tax_use', '=', 'sale'), ('company_id', 'parent_of', parent.company_id)]"
context="{'search_view_ref': 'account.account_tax_view_search'}"
options="{'no_create': True}"
required="not display_type"
invisible="display_type"
Expand Down
Loading