Debian Codegraph @

addons/sale_management/models/sale_order_line.py

raw symbols SCIP
1 # Part of Odoo. See LICENSE file for full copyright and licensing details.
2
3 from odoo import api, fields, models
4
5
6 class SaleOrderLine(models.Model):
7 _inherit = 'sale.order.line'
8 _description = "Sales Order Line"
9
10 # Section-related fields
11 is_optional = fields.Boolean(
12 string="Optional Line",
13 copy=True,
14 default=False,
15 ) # Whether this section's lines are optional in the portal.
16
17 # === COMPUTE METHODS === #
18
19 @api.depends('product_id')
20 def _compute_name(self):
21 # Take the description on the order template if the product is present in it
22 super()._compute_name()
23 for line in self:
24 if line.product_id and line.order_id.sale_order_template_id and line._use_template_name():
25 for template_line in line.order_id.sale_order_template_id.sale_order_template_line_ids:
26 if line.product_id == template_line.product_id and template_line.name:
27 # If a specific description was set on the template, use it
28 # Otherwise the description is handled by the super call
29 lang = line.order_id.partner_id.lang
30 line.name = template_line.with_context(lang=lang).name + line.with_context(lang=lang)._get_sale_order_line_multiline_description_variants()
31 break
32
33 def _use_template_name(self):
34 """ Allows overriding to avoid using the template lines descriptions for the sale order lines descriptions.
35 This is typically useful for 'configured' products, such as event_ticket or event_booth, where we need to have
36 specific configuration information inside description instead of the default values.
37 """
38 self.ensure_one()
39 return True
40
41 # === TOOLING ===#
42
43 def _is_line_optional(self):
44 """ Returns whether the line is optional or not.
45
46 A line is optional if it is directly under an optional (sub)section, or under a subsection
47 which is itself under an optional section.
48 """
49 self.ensure_one()
50 return (
51 self.parent_id.is_optional
52 or (
53 self.parent_id.display_type == 'line_subsection'
54 and self.parent_id.parent_id.is_optional
55 )
56 )
57
58 def _can_be_edited_on_portal(self):
59 return super()._can_be_edited_on_portal() and self._is_line_optional()