Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[17.0][IMP] product_contract: Set description under product name instead of description #1187

Merged
merged 1 commit into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions product_contract/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ invoice directly.
.. contents::
:local:

Configuration
=============

You can include the contract details on the sales order description by
using the following system parameters:

1. **Recurrency** -> product_contract.show_recurrency
2. **Invoicing Type** -> product_contract.show_invoicing_type
3. **Date** -> product_contract.show_date

Usage
=====

Expand Down
80 changes: 28 additions & 52 deletions product_contract/i18n/es.po
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 10.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-08-30 12:54+0000\n"
"PO-Revision-Date: 2024-08-30 15:06+0200\n"
"POT-Creation-Date: 2025-01-24 14:18+0000\n"
"PO-Revision-Date: 2025-01-24 15:19+0100\n"
"Last-Translator: Pedro M. Baeza <[email protected]>\n"
"Language-Team: Spanish (https://www.transifex.com/oca/teams/23907/es/)\n"
"Language: es\n"
Expand All @@ -20,6 +20,27 @@ msgstr ""
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"X-Generator: Poedit 3.0.1\n"

#. module: product_contract
#. odoo-python
#: code:addons/product_contract/models/sale_order_line.py:0
#, python-format
msgid "- Date: {}"
msgstr "- Fecha: {}"

#. module: product_contract
#. odoo-python
#: code:addons/product_contract/models/sale_order_line.py:0
#, python-format
msgid "- Invoicing Type: {}"
msgstr "- Tipo de facturación: {}"

#. module: product_contract
#. odoo-python
#: code:addons/product_contract/models/sale_order_line.py:0
#, python-format
msgid "- Recurrency: {}"
msgstr "- Recurrencia: {}"

#. module: product_contract
#: model_terms:ir.ui.view,arch_db:product_contract.contract_contract_customer_form_view
msgid "<span class=\"o_stat_text\">Sale Orders</span>"
Expand Down Expand Up @@ -361,6 +382,11 @@ msgstr "Producto"
msgid "Product Contract Configurator Wizard"
msgstr ""

#. module: product_contract
#: model:ir.model.fields,field_description:product_contract.field_sale_order_line__product_contract_description
msgid "Product Contract Description"
msgstr ""

#. module: product_contract
#: model:ir.model.fields,field_description:product_contract.field_product_contract_configurator__product_uom_qty
msgid "Quantity"
Expand Down Expand Up @@ -616,53 +642,3 @@ msgstr "Años"
#, python-format
msgid "You can't upsell or downsell a terminated contract"
msgstr "No puede vender o vender un contrato terminado"

#. module: product_contract
#. odoo-python
#: code:addons/product_contract/models/sale_order.py:0
#, python-format
msgid ""
"You must specify a contract template for '%(product_name)s' product in "
"'%(company_name)s' company."
msgstr ""
"Debes especificar una plantilla de contrato para el producto "
"'%(product_name)s' en la empresa '%(company_name)s'."

#. module: product_contract
#. odoo-python
#: code:addons/product_contract/models/sale_order_line.py:0
#, python-format
msgid ""
"{product}:\n"
" - Recurrency: {recurring_rule}\n"
" - Invoicing Type: {invoicing_type}\n"
" - Date: {date_text}\n"
" "
msgstr ""

#, python-format
#~ msgid ""
#~ "{product}\n"
#~ " - Recurrency: {recurring_rule}\n"
#~ " - Invoicing Type: {invoicing_type}\n"
#~ " - Date: {date_text}\n"
#~ " "
#~ msgstr ""
#~ "{product}\n"
#~ " - Periodicidad: {recurring_rule}\n"
#~ " - Tipo de facturación: {invoicing_type}\n"
#~ " - Fecha: {date_text}\n"
#~ " "

#~ msgid "Product Template"
#~ msgstr "Plantilla de producto"

#~ msgid "Sale Order"
#~ msgstr "Pedido de Venta"

#, python-format
#~ msgid ""
#~ "You must specify a contract template for '{}' product in '{}' company."
#~ msgstr ""
#~ "Debe especificar una plantilla de contrato para el producto '{}' en la "
#~ "compañía '{}'."
49 changes: 28 additions & 21 deletions product_contract/i18n/product_contract.pot
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,36 @@ msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 17.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2025-01-24 14:18+0000\n"
"PO-Revision-Date: 2025-01-24 14:18+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: product_contract
#. odoo-python
#: code:addons/product_contract/models/sale_order_line.py:0
#, python-format
msgid "- Date: {}"
msgstr ""

#. module: product_contract
#. odoo-python
#: code:addons/product_contract/models/sale_order_line.py:0
#, python-format
msgid "- Invoicing Type: {}"
msgstr ""

#. module: product_contract
#. odoo-python
#: code:addons/product_contract/models/sale_order_line.py:0
#, python-format
msgid "- Recurrency: {}"
msgstr ""

#. module: product_contract
#: model_terms:ir.ui.view,arch_db:product_contract.contract_contract_customer_form_view
msgid "<span class=\"o_stat_text\">Sale Orders</span>"
Expand Down Expand Up @@ -354,6 +377,11 @@ msgstr ""
msgid "Product Contract Configurator Wizard"
msgstr ""

#. module: product_contract
#: model:ir.model.fields,field_description:product_contract.field_sale_order_line__product_contract_description
msgid "Product Contract Description"
msgstr ""

#. module: product_contract
#: model:ir.model.fields,field_description:product_contract.field_product_contract_configurator__product_uom_qty
msgid "Quantity"
Expand Down Expand Up @@ -559,24 +587,3 @@ msgstr ""
#, python-format
msgid "You can't upsell or downsell a terminated contract"
msgstr ""

#. module: product_contract
#. odoo-python
#: code:addons/product_contract/models/sale_order.py:0
#, python-format
msgid ""
"You must specify a contract template for '%(product_name)s' product in "
"'%(company_name)s' company."
msgstr ""

#. module: product_contract
#. odoo-python
#: code:addons/product_contract/models/sale_order_line.py:0
#, python-format
msgid ""
"{product}:\n"
" - Recurrency: {recurring_rule}\n"
" - Invoicing Type: {invoicing_type}\n"
" - Date: {date_text}\n"
" "
msgstr ""
153 changes: 98 additions & 55 deletions product_contract/models/sale_order_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from odoo import _, api, fields, models
from odoo.exceptions import ValidationError
from odoo.tools import str2bool

MONTH_NB_MAPPING = {
"monthly": 1,
Expand Down Expand Up @@ -74,6 +75,9 @@
contract_start_date_method = fields.Selection(
related="product_id.contract_start_date_method"
)
product_contract_description = fields.Text(
compute="_compute_product_contract_description"
)

@api.constrains("contract_id")
def _check_contact_is_not_terminated(self):
Expand Down Expand Up @@ -307,64 +311,103 @@
start_date = start_date + relativedelta(day=31)
line.date_start = start_date

@api.depends("product_id")
def _compute_name(self):
res = super()._compute_name()
for line in self:
if line.is_contract:
date_text = ""
if line.contract_start_date_method == "manual":
date_text = "%s" % line.date_start
if line.date_end:
date_text += " -> %s" % line.date_end
else:
field_info = dict(
line._fields["contract_start_date_method"].get_description(
self.env
)
)
field_selection = dict(field_info.get("selection"))
start_method_label = field_selection.get(
line.contract_start_date_method
)
date_text = "%s" % start_method_label
if (
line.recurring_rule_type != "monthly"
and line.product_id["force_month_%s" % line.recurring_rule_type]
):
field_info = dict(
self.env["product.template"]
._fields["force_month_%s" % line.recurring_rule_type]
.get_description(self.env)
)
field_selection = dict(field_info.get("selection"))
force_month_label = field_selection.get(
line.product_id["force_month_%s" % line.recurring_rule_type]
)
date_text += " (%s)" % force_month_label
field_info = dict(
self._fields["recurring_rule_type"].get_description(self.env)
)
field_selection = dict(field_info.get("selection"))
recurring_rule_label = field_selection.get(line.recurring_rule_type)
def _get_product_contract_date_text(self):
self.ensure_one()
date_text = ""

Check warning on line 316 in product_contract/models/sale_order_line.py

View check run for this annotation

Codecov / codecov/patch

product_contract/models/sale_order_line.py#L315-L316

Added lines #L315 - L316 were not covered by tests
if self.contract_start_date_method == "manual":
date_text = "%s" % self.date_start

Check warning on line 318 in product_contract/models/sale_order_line.py

View check run for this annotation

Codecov / codecov/patch

product_contract/models/sale_order_line.py#L318

Added line #L318 was not covered by tests
if self.date_end:
date_text += " -> %s" % self.date_end

Check warning on line 320 in product_contract/models/sale_order_line.py

View check run for this annotation

Codecov / codecov/patch

product_contract/models/sale_order_line.py#L320

Added line #L320 was not covered by tests
else:
field_info = dict(

Check warning on line 322 in product_contract/models/sale_order_line.py

View check run for this annotation

Codecov / codecov/patch

product_contract/models/sale_order_line.py#L322

Added line #L322 was not covered by tests
self._fields["contract_start_date_method"].get_description(self.env)
)
field_selection = dict(field_info.get("selection"))
start_method_label = field_selection.get(self.contract_start_date_method)
date_text = start_method_label and "%s" % start_method_label

Check warning on line 327 in product_contract/models/sale_order_line.py

View check run for this annotation

Codecov / codecov/patch

product_contract/models/sale_order_line.py#L325-L327

Added lines #L325 - L327 were not covered by tests
if (
self.recurring_rule_type != "monthly"
and self.product_id["force_month_%s" % self.recurring_rule_type]
):
field_info = dict(
self._fields["recurring_invoicing_type"].get_description(self.env)
self.env["product.template"]
._fields["force_month_%s" % self.recurring_rule_type]
.get_description(self.env)
)
field_selection = dict(field_info.get("selection"))
invoicing_type_label = field_selection.get(
line.recurring_invoicing_type
)
line.name = _(
"""{product}:
- Recurrency: {recurring_rule}
- Invoicing Type: {invoicing_type}
- Date: {date_text}
"""
).format(
product=line.product_id.display_name,
recurring_rule=recurring_rule_label,
invoicing_type=invoicing_type_label,
date_text=date_text,
force_month_label = field_selection.get(

Check warning on line 338 in product_contract/models/sale_order_line.py

View check run for this annotation

Codecov / codecov/patch

product_contract/models/sale_order_line.py#L338

Added line #L338 was not covered by tests
self.product_id["force_month_%s" % self.recurring_rule_type]
Comment on lines +334 to +339
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is necessary to take into account whether the field is set or not before accessing it, or make it a required field in the product form view to prevent mistakes.
I set the field as empty intentionally, but the user can do the same. What do you think?
image

image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this could be attended in this other PR: #1188

)
date_text += " (%s)" % force_month_label
return date_text and _("- Date: {}").format(date_text)

Check warning on line 342 in product_contract/models/sale_order_line.py

View check run for this annotation

Codecov / codecov/patch

product_contract/models/sale_order_line.py#L341-L342

Added lines #L341 - L342 were not covered by tests

def _get_product_contract_recurring_rule_label(self):
self.ensure_one()
field_info = dict(self._fields["recurring_rule_type"].get_description(self.env))
field_selection = dict(field_info.get("selection"))
recurring_rule_label = field_selection.get(self.recurring_rule_type)
return recurring_rule_label and _("- Recurrency: {}").format(

Check warning on line 349 in product_contract/models/sale_order_line.py

View check run for this annotation

Codecov / codecov/patch

product_contract/models/sale_order_line.py#L345-L349

Added lines #L345 - L349 were not covered by tests
recurring_rule_label
)

def _get_product_contract_invoicing_type_label(self):
field_info = dict(

Check warning on line 354 in product_contract/models/sale_order_line.py

View check run for this annotation

Codecov / codecov/patch

product_contract/models/sale_order_line.py#L354

Added line #L354 was not covered by tests
self._fields["recurring_invoicing_type"].get_description(self.env)
)
field_selection = dict(field_info.get("selection"))
invoicing_type_label = field_selection.get(self.recurring_invoicing_type)
return invoicing_type_label and _("- Invoicing Type: {}").format(

Check warning on line 359 in product_contract/models/sale_order_line.py

View check run for this annotation

Codecov / codecov/patch

product_contract/models/sale_order_line.py#L357-L359

Added lines #L357 - L359 were not covered by tests
invoicing_type_label
)

@api.depends(
"product_id",
"date_start",
"date_end",
"recurring_rule_type",
"recurring_invoicing_type",
)
def _compute_product_contract_description(self):
self.product_contract_description = False

Check warning on line 371 in product_contract/models/sale_order_line.py

View check run for this annotation

Codecov / codecov/patch

product_contract/models/sale_order_line.py#L371

Added line #L371 was not covered by tests
for line in self:
if line.is_contract:
description = ""

Check warning on line 374 in product_contract/models/sale_order_line.py

View check run for this annotation

Codecov / codecov/patch

product_contract/models/sale_order_line.py#L374

Added line #L374 was not covered by tests
if (
recurring_rule_label
:= line._get_product_contract_recurring_rule_label()
):
description += recurring_rule_label + "||"

Check warning on line 379 in product_contract/models/sale_order_line.py

View check run for this annotation

Codecov / codecov/patch

product_contract/models/sale_order_line.py#L379

Added line #L379 was not covered by tests
if (
invoicing_type_label
:= line._get_product_contract_invoicing_type_label()
):
description += invoicing_type_label + "||"

Check warning on line 384 in product_contract/models/sale_order_line.py

View check run for this annotation

Codecov / codecov/patch

product_contract/models/sale_order_line.py#L384

Added line #L384 was not covered by tests
if date_text := line._get_product_contract_date_text():
description += date_text + "||"
line.product_contract_description = description

Check warning on line 387 in product_contract/models/sale_order_line.py

View check run for this annotation

Codecov / codecov/patch

product_contract/models/sale_order_line.py#L386-L387

Added lines #L386 - L387 were not covered by tests

@api.depends(
"date_start", "date_end", "recurring_rule_type", "recurring_invoicing_type"
)
def _compute_name(self):
res = super()._compute_name()
ICP = self.env["ir.config_parameter"].sudo()
for line in self:
if line.is_contract:
description = ""
if str2bool(ICP.get_param("product_contract.show_recurrency")) and (
recurring_rule_label
:= line._get_product_contract_recurring_rule_label()
):
description += "\n\t" + recurring_rule_label

Check warning on line 402 in product_contract/models/sale_order_line.py

View check run for this annotation

Codecov / codecov/patch

product_contract/models/sale_order_line.py#L402

Added line #L402 was not covered by tests
if str2bool(ICP.get_param("product_contract.show_invoicing_type")) and (
invoicing_type_label
:= line._get_product_contract_invoicing_type_label()
):
description += "\n\t" + invoicing_type_label

Check warning on line 407 in product_contract/models/sale_order_line.py

View check run for this annotation

Codecov / codecov/patch

product_contract/models/sale_order_line.py#L407

Added line #L407 was not covered by tests
if str2bool(ICP.get_param("product_contract.show_date")) and (
date_text := line._get_product_contract_date_text()
):
description += "\n\t" + date_text

Check warning on line 411 in product_contract/models/sale_order_line.py

View check run for this annotation

Codecov / codecov/patch

product_contract/models/sale_order_line.py#L411

Added line #L411 was not covered by tests
line.name = f"{line.product_id.display_name}{description}"
return res
5 changes: 5 additions & 0 deletions product_contract/readme/CONFIGURE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
You can include the contract details on the sales order description by using the following system parameters:

1. **Recurrency** -\> product_contract.show_recurrency
2. **Invoicing Type** -\> product_contract.show_invoicing_type
3. **Date** -\> product_contract.show_date
Loading
Loading