Skip to content

Commit

Permalink
Merge branch 'dhongu:17.0' into 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
VoicuStefan2001 authored Oct 28, 2024
2 parents 9288bf8 + c2b0c2c commit eb07bcf
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 86 deletions.
2 changes: 1 addition & 1 deletion deltatech_alternative/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

{
"name": "Products Alternative",
"version": "17.0.2.0.5",
"version": "17.0.2.0.7",
"author": "Terrabit, Dorin Hongu",
"website": "https://www.terrabit.ro",
"summary": "Alternative product codes",
Expand Down
60 changes: 18 additions & 42 deletions deltatech_alternative/models/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,23 @@
# See README.rst file on addons root folder for license details

from odoo import api, fields, models
from odoo.osv import expression
from odoo.tools.safe_eval import safe_eval


class ProductTemplate(models.Model):
_inherit = "product.template"

search_index = fields.Char(compute="_compute_search_index", store=True, index=True, compute_sudo=True)

alternative_code = fields.Char(
string="Alternative Code",
index=True,
inverse="_inverse_alternative_code",
compute="_compute_alternative_code",
unaccent=False,
)
alternative_ids = fields.One2many("product.alternative", "product_tmpl_id", string="Alternatives")

used_for = fields.Char(string="Used For")

@api.depends("name", "default_code", "alternative_ids.name", "seller_ids.product_code")
def _compute_search_index(self):
langs = self.env["res.lang"].search([("active", "=", True)])
langs = langs.mapped("code")
for product in self:
names = [product.with_context(lang=lang).name for lang in langs]
name_terms = list(set(names))
good_terms = [term for term in name_terms if term is not False]
search_index = " ".join(good_terms)

if product.default_code:
search_index = product.default_code + " " + search_index

terms = []
if product.seller_ids:
terms += [s.product_code for s in product.seller_ids if s.product_code]
if product.alternative_ids:
terms += [a.name for a in product.alternative_ids if a.name]

terms = list(set(terms))
search_index += " " + " ".join(terms)
product.search_index = search_index[:1000]

def _inverse_alternative_code(self):
for product in self:
if any(a.hide for a in product.alternative_ids):
Expand All @@ -65,29 +40,30 @@ def _compute_alternative_code(self):
code = "; ".join(codes)
product.alternative_code = code

@api.model
def _name_search(self, name, domain=None, operator="ilike", limit=None, order=None):
domain = domain or []
get_param = self.env["ir.config_parameter"].sudo().get_param
if name and safe_eval(get_param("deltatech_alternative_website.search_index", "False")):
domain2 = [("search_index", operator, name)]
return self._search(expression.AND([domain, domain2]), limit=limit)
else:
return super()._name_search(name, domain=domain, operator=operator, limit=limit, order=order)



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

@api.model
def _name_search(self, name, domain=None, operator="ilike", limit=None, order=None):
domain = domain or []
def _name_search(self, name, domain=None, operator='ilike', limit=None, order=None):
res = super()._name_search(name, domain=domain, operator=operator, limit=limit, order=order)
get_param = self.env["ir.config_parameter"].sudo().get_param
if name and safe_eval(get_param("deltatech_alternative_website.search_index", "False")):
domain = [("search_index", operator, name)]
return self._search(expression.AND([domain, domain]), limit=limit)
else:
return super()._name_search(name, domain=domain, operator=operator, limit=limit, order=order)
res_ids = list(res)
if name and safe_eval(get_param("alternative.search_name", "False")):
domain = [("name", operator, name)]
alternatives = self.env["product.alternative"].search(domain, limit=limit)
if alternatives:
product_tmpl_ids = alternatives.mapped("product_tmpl_id")
product_ids = self._search(
[("product_tmpl_id", "in", product_tmpl_ids.ids)],
limit=limit,
order=order,
)
res_ids.extend(list(product_ids))

return res_ids


class ProductAlternative(models.Model):
Expand Down
5 changes: 0 additions & 5 deletions deltatech_alternative/views/product_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,13 @@
</group>
<notebook position="inside">
<page string="Alternative">
<separator string="Alternative" colspan="4" />
<field name="alternative_ids" colspan="4" nolabel="1">
<tree editable="bottom">
<field name="sequence" widget="handle" />
<field name="name" />
<field name="hide" />
</tree>
</field>
<group>
<field name="search_index" />
</group>

</page>
</notebook>
</field>
Expand Down
20 changes: 2 additions & 18 deletions deltatech_alternative_website/models/product_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# See README.rst file on addons root folder for license details

from odoo import api, models
from odoo.tools.safe_eval import safe_eval


class ProductTemplate(models.Model):
Expand All @@ -12,21 +11,6 @@ class ProductTemplate(models.Model):
@api.model
def _search_get_detail(self, website, order, options):
values = super()._search_get_detail(website, order, options)

get_param = self.env["ir.config_parameter"].sudo().get_param

if safe_eval(get_param("deltatech_alternative_website.search_index", "False")):
values["search_fields"] = ["search_index"]
values["mapping"]["search_index"] = {
"name": "search_index",
"type": "text",
"match": True,
}
else:
values["search_fields"] += ["alternative_ids.name"]
values["mapping"]["alternative_ids.name"] = {
"name": "alternative_ids.name",
"type": "text",
"match": True,
}
values["search_fields"] += ["alternative_ids.name"]
values["mapping"]["alternative_ids.name"] = {"name": "alternative_ids.name", "type": "text", "match": True}
return values
1 change: 1 addition & 0 deletions deltatech_alternative_website/views/templates.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
active="True"
customize_show="True"
name="Used For"
priority="100"
>
<xpath expr="//p[@t-field='product.description_sale']" position="after">
<t t-if="product.used_for">
Expand Down
11 changes: 5 additions & 6 deletions deltatech_business_process/models/business_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,14 +306,13 @@ def _load_records(self, data_list, update=False):
return super()._load_records(data_list, update)

@api.model
def _name_search(self, name="", args=None, operator="ilike", limit=100, name_get_uid=None):
if args is None:
args = []
def _name_search(self, name, domain=None, operator='ilike', limit=None, order=None):
args = domain or []
project_id = self.env.context.get("default_project_id", False)
domain = [("code", "=", name)]
local_domain = [("code", "=", name)]
if project_id:
domain.append(("project_id", "=", project_id))
ids = list(self._search(domain + args, limit=limit))
local_domain.append(("project_id", "=", project_id))
ids = list(self._search(local_domain + args, limit=limit, order=order))

search_domain = [("name", operator, name)]
if ids:
Expand Down
6 changes: 2 additions & 4 deletions deltatech_contact/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@
{
"name": "Deltatech Contacts",
"summary": "New fields in partner",
"version": "17.0.1.4.4",
"version": "17.0.1.4.6",
"author": "Terrabit,Dorin Hongu",
"website": "https://www.terrabit.ro",
"category": "Administration",
"depends": ["base"],
"depends": ["base", "contacts"],
"license": "OPL-1",
"data": [
"views/res_partner_view.xml",
# 'security/partner_security.xml',
# 'security/ir.model.access.csv'
],
"images": ["static/description/main_screenshot.png"],
"installable": True,
Expand Down
12 changes: 5 additions & 7 deletions deltatech_contact/views/res_partner_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@
<field name="inherit_id" ref="base.view_partner_form" />
<field name="arch" type="xml">

<xpath expr="//field[@name='vat']" position="before">
<xpath expr="//div[hasclass('o_address_format')]" position="after">
<label for="id_nr" string="Card ID Number" invisible="is_company==True or type!='contact'" />
<div class="o_row" invisible="is_company==True or type!='contact'">
<field name="id_series" />
<field name="id_nr" />

<field name="id_series" placeholder="XX" />
<field name="id_nr" placeholder="123456" />
</div>
<label for="id_issued_by" string="Card ID Issued" invisible="is_company==True or type!='contact'" />
<div class="o_row" invisible="is_company==True or type!='contact'">
Expand All @@ -33,9 +32,8 @@
<group name="person_id" invisible="type!='contact'">
<label for="id_nr" string="Card ID Number" invisible="is_company==True or type!='contact'" />
<div class="o_row" invisible="is_company==True or type!='contact'">
<field name="id_series" />
<field name="id_nr" />

<field name="id_series" placeholder="XX" />
<field name="id_nr" placeholder="123456" />
</div>
<label
for="id_issued_by"
Expand Down
2 changes: 1 addition & 1 deletion deltatech_sale_pallet/i18n/ro.po
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,4 @@ msgstr "Linie comandă vânzare"
#. module: deltatech_sale_pallet
#: model_terms:ir.ui.view,arch_db:deltatech_sale_pallet.view_move_form
msgid "Show pallets status"
msgstr "Afișează starea paletelor"
msgstr "Afișează starea paleților"
9 changes: 7 additions & 2 deletions deltatech_test_system/models/res_config_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ def get_installed_modules(self):
def get_neutralization_queries(self, modules):
# neutralization for each module
for module in modules:
filename = odoo.tools.file_path(f"{module}/data/neutralize.sql")
try:
filename = odoo.tools.file_path(f"{module}/data/neutralize.sql")
except FileNotFoundError:
continue
if filename:
with odoo.tools.misc.file_open(filename) as file:
yield file.read().strip()
Expand All @@ -41,7 +44,9 @@ def neutralize_database(self):
_logger.info("Neutralization finished")

def set_values(self):
get_param = self.env["ir.config_parameter"].sudo().get_param
is_neutralized = get_param("database.is_neutralized", default=False)
res = super().set_values()
if self.database_is_neutralized:
if not is_neutralized and self.database_is_neutralized:
self.neutralize_database()
return res

0 comments on commit eb07bcf

Please sign in to comment.