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

[16.0] [MIG] shopinvader_sale_packaging #1400

Closed
Closed
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
2 changes: 0 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,9 @@ exclude: |
^shopinvader_sale_automatic_workflow/|
^shopinvader_sale_communication/|
^shopinvader_sale_coupon/|
^shopinvader_sale_packaging/|
^shopinvader_sale_packaging_wishlist/|
^shopinvader_sale_profile/|
^shopinvader_sale_report/|
^shopinvader_search_engine/|
^shopinvader_wishlist/|
# END NOT INSTALLABLE ADDONS
# Files and folders generated by bots, to avoid loops
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# generated from manifests external_dependencies
extendable_pydantic>=1.0.0
extendable_pydantic>=1.1.0
fastapi
openupgradelib
pydantic>=2.0.0
unidecode
1 change: 1 addition & 0 deletions setup/shopinvader_product/odoo/addons/shopinvader_product
6 changes: 6 additions & 0 deletions setup/shopinvader_product/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
6 changes: 6 additions & 0 deletions setup/shopinvader_product_description/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
6 changes: 6 additions & 0 deletions setup/shopinvader_product_sale_packaging/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
6 changes: 6 additions & 0 deletions setup/shopinvader_product_seo/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
6 changes: 6 additions & 0 deletions setup/shopinvader_restapi_sale_packaging/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
6 changes: 6 additions & 0 deletions setup/shopinvader_search_engine/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
75 changes: 75 additions & 0 deletions shopinvader_product/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
===================
Shopinvader Product
===================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fodoo--shopinvader-lightgray.png?logo=github
:target: https://github.com/OCA/odoo-shopinvader/tree/16.0/shopinvader_product
:alt: OCA/odoo-shopinvader
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/odoo-shopinvader-16-0/odoo-shopinvader-16-0-shopinvader_product
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/webui/builds.html?repo=OCA/odoo-shopinvader&target_branch=16.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This addon makes products (and categories) suitable for shopinvader.
Adding revelant fields and pydantic schemas for serialization.

**Table of contents**

.. contents::
:local:

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/odoo-shopinvader/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/odoo-shopinvader/issues/new?body=module:%20shopinvader_product%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
~~~~~~~

* ACSONE SA/NV

Contributors
~~~~~~~~~~~~

* Laurent Mignon <[email protected]>
* Quentin Groulard <[email protected]>

Maintainers
~~~~~~~~~~~

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/odoo-shopinvader <https://github.com/OCA/odoo-shopinvader/tree/16.0/shopinvader_product>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 2 additions & 0 deletions shopinvader_product/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import models
from . import schemas
23 changes: 23 additions & 0 deletions shopinvader_product/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2023 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
"name": "Shopinvader Product",
"summary": """Adds shopinvader product fields and schemas""",
"version": "16.0.1.0.0",
"license": "AGPL-3",
"author": "ACSONE SA/NV",
"website": "https://github.com/shopinvader/odoo-shopinvader",
"depends": [
"product",
"pydantic",
"extendable",
"extendable_fastapi",
],
"data": ["views/product_category.xml", "views/product_template.xml"],
"demo": [],
"external_dependencies": {
"python": ["extendable_pydantic>=1.1.0", "pydantic>=2.0.0", "unidecode"]
},
"installable": True,
}
2 changes: 2 additions & 0 deletions shopinvader_product/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import category
from . import product_product
80 changes: 80 additions & 0 deletions shopinvader_product/models/category.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Copyright 2023 ACSONE SA/NV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

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


class ProductCategory(models.Model):
_inherit = "product.category"
# V13 restore translate on category name...
# This code is a transversal fix and should go into a dedicated addon...
# The translate=True has been removed in
# https://github.com/odoo/odoo/pull/36717 to workaround a bug introduced
# in https://github.com/odoo/odoo/pull/16220 To avoid a bug into the seach
# on category name, we must also restore the name_get method and
# name_search
# see also https://github.com/odoo/odoo/issues/22060#issuecomment-356567683
_rec_name = None

name = fields.Char(translate=True)

def name_get(self):
def get_names(cat):
"""Return the list [cat.name, cat.parent_id.name, ...]"""
res = []
while cat and cat.id:
res.append(cat.name)
cat = cat.parent_id
return res

return [(cat.id, " / ".join(reversed(get_names(cat)))) for cat in self]

@api.model
def name_search(self, name, args=None, operator="ilike", limit=100):
if not args:
args = []
if name:
# Be sure name_search is symetric to name_get
category_names = name.split(" / ")
parents = list(category_names)
child = parents.pop()
domain = [("name", operator, child)]
if parents:
names_ids = self.name_search(
" / ".join(parents),
args=args,
operator="ilike",
limit=limit,
)
category_ids = [name_id[0] for name_id in names_ids]
if operator in expression.NEGATIVE_TERM_OPERATORS:
categories = self.search([("id", "not in", category_ids)])
domain = expression.OR(
[[("parent_id", "in", categories.ids)], domain]
)
else:
domain = expression.AND(
[[("parent_id", "in", category_ids)], domain]
)
for i in range(1, len(category_names)):
domain = [
# fmt: off
[
(
"name",
operator,
" / ".join(category_names[-1 - i:]),
)
],
# fmt: on
domain
]
if operator in expression.NEGATIVE_TERM_OPERATORS:
domain = expression.AND(domain)
else:
domain = expression.OR(domain)
categories = self.search(expression.AND([domain, args]), limit=limit)
else:
categories = self.search(args, limit=limit)
return categories.name_get()
35 changes: 35 additions & 0 deletions shopinvader_product/models/product_product.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Copyright 2017 Akretion (http://www.akretion.com).
# @author Sébastien BEAU <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, fields, models

from .tools import sanitize_attr_name


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

variant_attributes = fields.Serialized(
compute="_compute_variant_attributes", string="Shopinvader Attributes"
)
attribute_value_ids = fields.Many2many(
comodel_name="product.attribute.value",
compute="_compute_attribute_value_ids",
readonly=True,
)

def _compute_variant_attributes(self):
for record in self:
variant_attributes = dict()
for att_value in record.attribute_value_ids:
sanitized_key = sanitize_attr_name(att_value.attribute_id)
variant_attributes[sanitized_key] = att_value.name
record.variant_attributes = variant_attributes

@api.depends("product_template_attribute_value_ids")
def _compute_attribute_value_ids(self):
for record in self:
record.attribute_value_ids = record.mapped(
"product_template_attribute_value_ids.product_attribute_value_id"
)
17 changes: 17 additions & 0 deletions shopinvader_product/models/tools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2017 Akretion (http://www.akretion.com).
# @author Sébastien BEAU <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

import logging

_logger = logging.getLogger(__name__)

try:
from unidecode import unidecode
except ImportError:
_logger.debug("Cannot `import unidecode`.")


def sanitize_attr_name(attribute):
key = attribute.name
return unidecode(key.replace(" ", "_").lower())
2 changes: 2 additions & 0 deletions shopinvader_product/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* Laurent Mignon <[email protected]>
* Quentin Groulard <[email protected]>
2 changes: 2 additions & 0 deletions shopinvader_product/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This addon makes products (and categories) suitable for shopinvader.
Adding revelant fields and pydantic schemas for serialization.
2 changes: 2 additions & 0 deletions shopinvader_product/schemas/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import category
from . import product
42 changes: 42 additions & 0 deletions shopinvader_product/schemas/category.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Copyright 2023 ACSONE SA/NV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo.addons.extendable_fastapi import StrictExtendableBaseModel


class ShortShopinvaderCategory(StrictExtendableBaseModel):
id: int
name: str
level: int
parent: "ShortShopinvaderCategory" | None = None
childs: list["ShortShopinvaderCategory"] = []

@classmethod
def from_shopinvader_category(cls, odoo_rec, with_hierarchy=False):
obj = cls.model_construct(
id=odoo_rec.record_id,
name=odoo_rec.name,
level=odoo_rec.short_description,
)
if with_hierarchy:
obj.parent = (
ShopinvaderCategory.from_shopinvader_category(
odoo_rec.shopinvader_parent_id
)
or None
)
obj.childs = [
ShopinvaderCategory.from_shopinvader_category(child)
for child in odoo_rec.shopinvader_child_ids
]
return obj


class ShopinvaderCategory(ShortShopinvaderCategory):
sequence: int | None = None

@classmethod
def from_shopinvader_category(cls, odoo_rec):
obj = super().from_shopinvader_category(odoo_rec, with_hierarchy=True)
obj.sequence = odoo_rec.sequence or None
return obj
Loading