[IMP] sale_project: Include Archived Projects in Stat Button View
[Context] Sales Order can be connected to projects. Before this commit archived projects were counted in the stat-button, but not in the related to stat-button project kanban view. We want to show archived (i.e. "non active") projects in both. [Reproduce behaviour before this commit]: - run odoo 15 with: sale_management,project,timesheet_grid - In Project, create: - project A - project B - In Sales/Products/Products, create: - product A (set: type="Service", Create on Order="Task", project="project A") - product B (set: type="Service", Create on Order="Task", project="project B") - In Salse/Orders/Quotations: - Create Quotation - add "product A" and "product B" - save & Confirm - OBSERVE: stat-button "projects" shows 2 projects - Click on: stat-button "projects" - OBSERVE: kanban view shows 2 projects - Archive one of project - go Project/"Project A"/Edit/Action/Archive (require debug mode) - Go back to created Quotation - OBSERVE (Desired): stat-button "projects" shows 2 projects - Click on: stat-button "projects" and OBSERVE - OBSERVE (Not-Desired): kanban view shows 1 projects (it excluded archived one) [Fix] Modified domain in the function/action related to the stat-button. opw-3500711 closes odoo/odoo#140364 X-original-commit: eef4506f32f09dcda9990556e55131bc17855dcc Signed-off-by: Xavier Bol (xbo) <xbo@odoo.com>
This commit is contained in:
@@ -115,7 +115,6 @@ class SaleOrder(models.Model):
|
||||
projects = order.order_line.mapped('product_id.project_id')
|
||||
projects |= order.order_line.mapped('project_id')
|
||||
projects |= order.project_id
|
||||
projects = projects.filtered('active')
|
||||
projects |= projects_per_so[order.id or order._origin.id]
|
||||
if not is_project_manager:
|
||||
projects = projects._filter_access_rules('read')
|
||||
@@ -201,7 +200,7 @@ class SaleOrder(models.Model):
|
||||
action = {
|
||||
'type': 'ir.actions.act_window',
|
||||
'name': _('Projects'),
|
||||
'domain': ['|', ('sale_order_id', '=', self.id), ('id', 'in', self.project_ids.ids)],
|
||||
'domain': ['|', ('sale_order_id', '=', self.id), ('id', 'in', self.with_context(active_test=False).project_ids.ids), ('active', 'in', [True, False])],
|
||||
'res_model': 'project.project',
|
||||
'views': [(False, 'kanban'), (False, 'tree'), (False, 'form')],
|
||||
'view_mode': 'kanban,tree,form',
|
||||
@@ -212,7 +211,7 @@ class SaleOrder(models.Model):
|
||||
'default_allow_billable': 1,
|
||||
}
|
||||
}
|
||||
if len(self.project_ids) == 1:
|
||||
if len(self.with_context(active_test=False).project_ids) == 1:
|
||||
action.update({'views': [(False, 'form')], 'res_id': self.project_ids.id})
|
||||
return action
|
||||
|
||||
|
||||
@@ -495,3 +495,64 @@ class TestSaleProject(TestSaleProjectCommon):
|
||||
self.assertEqual(sale_order.analytic_account_id.company_id, sale_order.project_ids.company_id, "The company_id of the account created should be the company of the project.")
|
||||
self.assertEqual(sale_order.analytic_account_id.plan_id, project_plan, "The plan of the account created should be the default analytic plan of the setting")
|
||||
self.assertEqual(sale_order.analytic_account_id, sale_order.project_ids.analytic_account_id, "The project created for the SO and the SO should have the same account.")
|
||||
|
||||
def test_include_archived_projects_in_stat_btn_related_view(self):
|
||||
"""Checks if the project stat-button action includes both archived and active projects."""
|
||||
# Setup
|
||||
project_A = self.env['project.project'].create({'name': 'Project_A'})
|
||||
project_B = self.env['project.project'].create({'name': 'Project_B'})
|
||||
|
||||
product_A = self.env['product.product'].create({
|
||||
'name': 'product A',
|
||||
'list_price': 1.0,
|
||||
'type': 'service',
|
||||
'service_tracking': 'task_global_project',
|
||||
'project_id':project_A.id,
|
||||
})
|
||||
product_B = self.env['product.product'].create({
|
||||
'name': 'product B',
|
||||
'list_price': 2.0,
|
||||
'type': 'service',
|
||||
'service_tracking': 'task_global_project',
|
||||
'project_id':project_B.id,
|
||||
})
|
||||
|
||||
sale_order = self.env['sale.order'].with_context(tracking_disable=True).create({
|
||||
'partner_id': self.partner.id,
|
||||
'partner_invoice_id': self.partner.id,
|
||||
'partner_shipping_id': self.partner.id,
|
||||
})
|
||||
|
||||
SaleOrderLine = self.env['sale.order.line'].with_context(tracking_disable=True)
|
||||
SaleOrderLine.create({
|
||||
'name': product_A.name,
|
||||
'product_id': product_A.id,
|
||||
'product_uom_qty': 10,
|
||||
'price_unit': product_A.list_price,
|
||||
'order_id': sale_order.id,
|
||||
})
|
||||
SaleOrderLine.create({
|
||||
'name': product_B.name,
|
||||
'product_id': product_B.id,
|
||||
'product_uom_qty': 10,
|
||||
'price_unit': product_B.list_price,
|
||||
'order_id': sale_order.id,
|
||||
})
|
||||
|
||||
def get_project_ids_from_action_domain(action):
|
||||
for el in action['domain']:
|
||||
if len(el) == 3 and el[0] == 'id' and el[1] == 'in':
|
||||
domain_proj_ids = el[2]
|
||||
break
|
||||
else:
|
||||
raise Exception(f"Couldn't find projects ids in the following action domain: {action['domain']}")
|
||||
return domain_proj_ids
|
||||
|
||||
# Check if button action includes both projects BEFORE archivization
|
||||
action = sale_order.action_view_project_ids()
|
||||
self.assertEqual(len(get_project_ids_from_action_domain(action)), 2, "Domain should contain 2 projects.")
|
||||
|
||||
# Check if button action includes both projects AFTER archivization
|
||||
project_B.write({'active': False})
|
||||
action = sale_order.action_view_project_ids()
|
||||
self.assertEqual(len(get_project_ids_from_action_domain(action)), 2, "Domain should contain 2 projects. (one archived, one not)")
|
||||
|
||||
Reference in New Issue
Block a user