[FIX] sale{_timesheet}: avoid using allowed_so_line_ids

Before this commit, the `allowed_so_line_ids` has been introduced
to always use `_default_sale_line_domain` method in the domain of
`so_line` field and so instead of easing the domain in the field definition
we will be able to override the domain by overriding `_default_sale_line_domain`
method. However, since in `sale_timesheet` module, the new domain will contain
a dynamic value in the right part of a leaf
(`('order_partner_id', 'child_of', commercial_partner_id)`), the
`allowed_so_line_ids` is instead use in the domain of `so_line` field to
easily add that leaf in the domain returned `_default_sale_line_domain`
in the compute method of that field. The problem is the number of SOLs
fetched could be really huge and caused a performance issues.

This commit reverts the commit b7491b5b94 by
- deprecating the `allowed_so_line_ids`, that is, that field will
  now always get an empty recordset.
- deprecating the `_default_sale_line_domain` method, that is the method
  will no longer be used
- manually adding the domain instead of calling `_default_sale_line_domain`
- altering the domain when the `sale_timesheet` module is installed to
  get the same domain used in the `sale_line_id` of `project.task` model

closes odoo/odoo#149747

Signed-off-by: Xavier Bol (xbo) <xbo@odoo.com>
This commit is contained in:
Xavier Bol (xbo)
2024-01-18 01:34:16 +00:00
parent 04a894c936
commit 72f3e40a0c
3 changed files with 14 additions and 9 deletions
+5 -6
View File
@@ -7,21 +7,20 @@ from odoo import fields, models
class AccountAnalyticLine(models.Model):
_inherit = "account.analytic.line"
# [XBO] TODO: remove me in master
allowed_so_line_ids = fields.Many2many('sale.order.line', compute='_compute_allowed_so_line_ids')
so_line = fields.Many2one('sale.order.line', string='Sales Order Item', domain="[('id', 'in', allowed_so_line_ids)]")
so_line = fields.Many2one('sale.order.line', string='Sales Order Item', domain=[('qty_delivered_method', '=', 'analytic')])
def _default_sale_line_domain(self):
""" This is only used for delivered quantity of SO line based on analytic line, and timesheet
(see sale_timesheet). This can be override to allow further customization.
[XBO] TODO: remove me in master
"""
self.ensure_one()
return [('qty_delivered_method', '=', 'analytic')]
def _compute_allowed_so_line_ids(self):
for timesheet in self:
domain = timesheet._default_sale_line_domain()
timesheet.allowed_so_line_ids = self.env['sale.order.line'].search(domain)
# [XBO] TODO: remove me in master
self.allowed_so_line_ids = False
class AccountAnalyticApplicability(models.Model):
_inherit = 'account.analytic.applicability'
+9 -1
View File
@@ -26,6 +26,13 @@ class AccountAnalyticLine(models.Model):
commercial_partner_id = fields.Many2one('res.partner', compute="_compute_commercial_partner")
timesheet_invoice_id = fields.Many2one('account.move', string="Invoice", readonly=True, copy=False, help="Invoice created from the timesheet", index='btree_not_null')
so_line = fields.Many2one(compute="_compute_so_line", store=True, readonly=False,
domain="""[
('qty_delivered_method', 'in', ['analytic', 'timesheet']),
('order_partner_id', '=', commercial_partner_id),
('is_service', '=', True),
('is_expense', '=', False),
('state', '=', 'sale')
]""",
help="Sales order item to which the time spent will be added in order to be invoiced to your customer. Remove the sales order item for the timesheet entry to be non-billable.")
# we needed to store it only in order to be able to groupby in the portal
order_id = fields.Many2one(related='so_line.order_id', store=True, readonly=True, index=True)
@@ -33,6 +40,7 @@ class AccountAnalyticLine(models.Model):
allow_billable = fields.Boolean(related="project_id.allow_billable")
def _default_sale_line_domain(self):
# [XBO] TODO: remove me in master
return expression.OR([[
('is_service', '=', True),
('is_expense', '=', False),
@@ -40,8 +48,8 @@ class AccountAnalyticLine(models.Model):
('order_partner_id', 'child_of', self.sudo().commercial_partner_id.ids)
], super()._default_sale_line_domain()])
@api.depends('commercial_partner_id')
def _compute_allowed_so_line_ids(self):
# [XBO] TODO: remove me in master
super()._compute_allowed_so_line_ids()
@api.depends('project_id.partner_id.commercial_partner_id', 'task_id.partner_id.commercial_partner_id')
@@ -42,7 +42,6 @@
<field name="commercial_partner_id" column_invisible="True" groups="sales_team.group_sale_salesman"/>
<field name="is_so_line_edited" column_invisible="True" groups="sales_team.group_sale_salesman"/>
<field name="allow_billable" column_invisible="True" groups="sales_team.group_sale_salesman"/>
<field name="allowed_so_line_ids" column_invisible="1"/>
<field name="so_line" widget="so_line_field" optional="show" options="{'no_create': True, 'no_open': True}" context="{'create': False, 'edit': False, 'delete': False}" invisible="not allow_billable" readonly="readonly_timesheet" placeholder="Non-billable" groups="sales_team.group_sale_salesman"/>
</xpath>
</field>
@@ -57,7 +56,6 @@
<field name="commercial_partner_id" invisible="1" groups="sales_team.group_sale_salesman"/>
<field name="is_so_line_edited" invisible="1" groups="sales_team.group_sale_salesman"/>
<field name="allow_billable" invisible="1" groups="sales_team.group_sale_salesman"/>
<field name="allowed_so_line_ids" invisible="1"/>
<field name="so_line" widget="so_line_field" options='{"no_create": True}' context="{'create': False, 'edit': False, 'delete': False, 'with_price_unit': True}" invisible="not allow_billable" readonly="readonly_timesheet" placeholder="Non-billable" groups="sales_team.group_sale_salesman"/>
</xpath>
<xpath expr="//group" position="before">