File: product.py

package info (click to toggle)
odoo 18.0.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 878,716 kB
  • sloc: javascript: 927,937; python: 685,670; xml: 388,524; sh: 1,033; sql: 415; makefile: 26
file content (24 lines) | stat: -rw-r--r-- 905 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# Part of Odoo. See LICENSE file for full copyright and licensing details.

import re

from odoo import models


class ProductProduct(models.Model):
    _inherit = 'product.product'

    def _compute_display_name(self):
        """ In a string consisting of space-delimited substrings, force a double-space between
        substrings where (when looking right to left) the first substring ends with a numeral and
        the second begins with an Arabic character.
        """
        def repl(match_occurrence):
            # group(1): (\d) == numeral
            # group(3): ([\u0600-\u06FF]) == Arabic character
            return f'{match_occurrence.group(1)}  {match_occurrence.group(3)}'

        super()._compute_display_name()
        for product in self:
            if product.display_name:
                product.display_name = re.sub(r'(\d)(\s)([\u0600-\u06FF])', repl, product.display_name)