From 313123c5fb58a5ff011f52b8f2da9486bfe8a94a Mon Sep 17 00:00:00 2001 From: Victor Feyens Date: Thu, 30 Dec 2021 17:21:51 +0000 Subject: [PATCH] [IMP] website_sale: split python files by classes Part-of: odoo/odoo#82094 --- addons/website_sale/models/__init__.py | 1 + addons/website_sale/models/sale_order.py | 28 ---------------- addons/website_sale/models/sale_order_line.py | 32 +++++++++++++++++++ 3 files changed, 33 insertions(+), 28 deletions(-) create mode 100644 addons/website_sale/models/sale_order_line.py diff --git a/addons/website_sale/models/__init__.py b/addons/website_sale/models/__init__.py index 4fb8c200a4c..a2aaec03e5c 100644 --- a/addons/website_sale/models/__init__.py +++ b/addons/website_sale/models/__init__.py @@ -19,6 +19,7 @@ from . import res_config_settings from . import res_country from . import res_partner from . import sale_order +from . import sale_order_line from . import website from . import website_page from . import website_snippet_filter diff --git a/addons/website_sale/models/sale_order.py b/addons/website_sale/models/sale_order.py index bf1e23aafac..ff41a9cb3f2 100644 --- a/addons/website_sale/models/sale_order.py +++ b/addons/website_sale/models/sale_order.py @@ -359,31 +359,3 @@ class SaleOrder(models.Model): if not order.transaction_ids and not order.amount_total and self._context.get('send_email'): order._send_order_confirmation_mail() return res - - -class SaleOrderLine(models.Model): - _inherit = "sale.order.line" - - name_short = fields.Char(compute="_compute_name_short") - - linked_line_id = fields.Many2one('sale.order.line', string='Linked Order Line', domain="[('order_id', '!=', order_id)]", ondelete='cascade') - option_line_ids = fields.One2many('sale.order.line', 'linked_line_id', string='Options Linked') - - def get_sale_order_line_multiline_description_sale(self, product): - description = super(SaleOrderLine, self).get_sale_order_line_multiline_description_sale(product) - if self.linked_line_id: - description += "\n" + _("Option for: %s", self.linked_line_id.product_id.display_name) - if self.option_line_ids: - description += "\n" + '\n'.join([_("Option: %s", option_line.product_id.display_name) for option_line in self.option_line_ids]) - return description - - @api.depends('product_id.display_name') - def _compute_name_short(self): - """ Compute a short name for this sale order line, to be used on the website where we don't have much space. - To keep it short, instead of using the first line of the description, we take the product name without the internal reference. - """ - for record in self: - record.name_short = record.product_id.with_context(display_default_code=False).display_name - - def get_description_following_lines(self): - return self.name.splitlines()[1:] diff --git a/addons/website_sale/models/sale_order_line.py b/addons/website_sale/models/sale_order_line.py new file mode 100644 index 00000000000..abb09d1f2f1 --- /dev/null +++ b/addons/website_sale/models/sale_order_line.py @@ -0,0 +1,32 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import api, models, fields, _ + + +class SaleOrderLine(models.Model): + _inherit = "sale.order.line" + + name_short = fields.Char(compute="_compute_name_short") + + linked_line_id = fields.Many2one('sale.order.line', string='Linked Order Line', domain="[('order_id', '!=', order_id)]", ondelete='cascade') + option_line_ids = fields.One2many('sale.order.line', 'linked_line_id', string='Options Linked') + + def get_sale_order_line_multiline_description_sale(self, product): + description = super(SaleOrderLine, self).get_sale_order_line_multiline_description_sale(product) + if self.linked_line_id: + description += "\n" + _("Option for: %s", self.linked_line_id.product_id.display_name) + if self.option_line_ids: + description += "\n" + '\n'.join([_("Option: %s", option_line.product_id.display_name) for option_line in self.option_line_ids]) + return description + + @api.depends('product_id.display_name') + def _compute_name_short(self): + """ Compute a short name for this sale order line, to be used on the website where we don't have much space. + To keep it short, instead of using the first line of the description, we take the product name without the internal reference. + """ + for record in self: + record.name_short = record.product_id.with_context(display_default_code=False).display_name + + def get_description_following_lines(self): + return self.name.splitlines()[1:]