From 584f05222881a7728572ec08656950d37ea1f42e Mon Sep 17 00:00:00 2001 From: Sergey Krylov Date: Wed, 19 Feb 2025 14:17:28 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9D=D0=B0=D1=87=D0=B0=D0=BB=D1=8C=D0=BD?= =?UTF-8?q?=D0=BE=D0=B5=20=D0=BD=D0=B0=D0=BF=D0=BE=D0=BB=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __init__.py | 4 +++ __manifest__.py | 14 +++++++++++ i18n/ru.po | 28 +++++++++++++++++++++ i18n/sale_service.pot | 26 +++++++++++++++++++ models/__init__.py | 4 +++ models/sale_order_line.py | 53 +++++++++++++++++++++++++++++++++++++++ 6 files changed, 129 insertions(+) create mode 100644 __init__.py create mode 100644 __manifest__.py create mode 100644 i18n/ru.po create mode 100644 i18n/sale_service.pot create mode 100644 models/__init__.py create mode 100644 models/sale_order_line.py diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..dc5e6b6 --- /dev/null +++ b/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from . import models diff --git a/__manifest__.py b/__manifest__.py new file mode 100644 index 0000000..41f52f7 --- /dev/null +++ b/__manifest__.py @@ -0,0 +1,14 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. +{ + 'name': "Sales - Service", + 'summary': "Interaction between Sales and services apps (project and planning)", + 'description': """ +Allows to display sale information in the SOL services apps +=========================================================== +Additional information is displayed in the name of the SOL when it is used in services apps (project and planning). +""", + 'category': 'Hidden', + 'depends': ['sale_management'], + 'license': 'LGPL-3', +} diff --git a/i18n/ru.po b/i18n/ru.po new file mode 100644 index 0000000..737b59d --- /dev/null +++ b/i18n/ru.po @@ -0,0 +1,28 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_service +# +# Translators: +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 17.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2023-10-26 21:55+0000\n" +"PO-Revision-Date: 2024-01-30 15:14+0400\n" +"Last-Translator: \n" +"Language-Team: Russian (https://app.transifex.com/odoo/teams/41243/ru/)\n" +"Language: ru\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=4; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<12 || n%100>14) ? 1 : n%10==0 || (n%10>=5 && n%10<=9) || (n%100>=11 && n%100<=14)? 2 : 3);\n" + +#. module: sale_service +#: model:ir.model.fields,field_description:sale_service.field_sale_order_line__is_service +msgid "Is a Service" +msgstr "Является услугой" + +#. module: sale_service +#: model:ir.model,name:sale_service.model_sale_order_line +msgid "Sales Order Line" +msgstr "Позиция заказа на продажу" diff --git a/i18n/sale_service.pot b/i18n/sale_service.pot new file mode 100644 index 0000000..56da84a --- /dev/null +++ b/i18n/sale_service.pot @@ -0,0 +1,26 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_service +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 17.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2023-10-26 21:55+0000\n" +"PO-Revision-Date: 2023-10-26 21:55+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: sale_service +#: model:ir.model.fields,field_description:sale_service.field_sale_order_line__is_service +msgid "Is a Service" +msgstr "" + +#. module: sale_service +#: model:ir.model,name:sale_service.model_sale_order_line +msgid "Sales Order Line" +msgstr "" diff --git a/models/__init__.py b/models/__init__.py new file mode 100644 index 0000000..83c06ee --- /dev/null +++ b/models/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from . import sale_order_line diff --git a/models/sale_order_line.py b/models/sale_order_line.py new file mode 100644 index 0000000..8fb5b56 --- /dev/null +++ b/models/sale_order_line.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from itertools import groupby + +from odoo import api, fields, models +from odoo.tools import format_amount +from odoo.tools.sql import column_exists, create_column + + +class SaleOrderLine(models.Model): + _inherit = "sale.order.line" + + # used to know if generate a task and/or a project, depending on the product settings + is_service = fields.Boolean("Is a Service", compute='_compute_is_service', store=True, compute_sudo=True) + + @api.depends('product_id.type') + def _compute_is_service(self): + for so_line in self: + so_line.is_service = so_line.product_id.type == 'service' + + def _auto_init(self): + """ + Create column to stop ORM from computing it himself (too slow) + """ + if not column_exists(self.env.cr, 'sale_order_line', 'is_service'): + create_column(self.env.cr, 'sale_order_line', 'is_service', 'bool') + self.env.cr.execute(""" + UPDATE sale_order_line line + SET is_service = (pt.type = 'service') + FROM product_product pp + LEFT JOIN product_template pt ON pt.id = pp.product_tmpl_id + WHERE pp.id = line.product_id + """) + return super()._auto_init() + + def _additional_name_per_id(self): + name_per_id = super()._additional_name_per_id() if not self.env.context.get('hide_partner_ref') else {} + if not self.env.context.get('with_price_unit'): + return name_per_id + + sols_list = [list(sols) for dummy, sols in groupby(self, lambda sol: (sol.order_id, sol.product_id))] + for sols in sols_list: + if len(sols) <= 1 or not all(sol.is_service for sol in sols): + continue + for line in sols: + additional_name = name_per_id.get(line.id) + name = format_amount(self.env, line.price_unit, line.currency_id) + if additional_name: + name += f' {additional_name}' + name_per_id[line.id] = f'- {name}' + + return name_per_id