Skip to content

Commit

Permalink
Merge PR #353 into 16.0
Browse files Browse the repository at this point in the history
Signed-off-by pedrobaeza
  • Loading branch information
OCA-git-bot committed Jun 22, 2024
2 parents 5589406 + 2351a7b commit e128707
Show file tree
Hide file tree
Showing 47 changed files with 2,547 additions and 13 deletions.
24 changes: 14 additions & 10 deletions product_variant_configurator/models/product_configurator.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
class ProductConfigurator(models.AbstractModel):
_name = "product.configurator"
_description = "Product Configurator"
_partner_id_field = "partner_id"

product_tmpl_id = fields.Many2one(
string="Product Template", comodel_name="product.template", auto_join=True
Expand All @@ -26,7 +27,7 @@ class ProductConfigurator(models.AbstractModel):
copy=True,
)
price_extra = fields.Float(
compute="_compute_can_be_created",
compute="_compute_price_extra",
digits="Product Price",
help="Price Extra: Extra price for the variant with the currently "
"selected attributes values on sale price. eg. 200 price extra, "
Expand All @@ -43,6 +44,11 @@ class ProductConfigurator(models.AbstractModel):
can_create_product = fields.Boolean(compute="_compute_can_be_created")
create_product_variant = fields.Boolean(string="Create product now!")

@api.depends("product_attribute_ids", "product_attribute_ids.price_extra")
def _compute_price_extra(self):
for rec in self:
rec.price_extra = sum(rec.mapped("product_attribute_ids.price_extra"))

@api.depends(
"product_attribute_ids", "product_attribute_ids.value_id", "product_id"
)
Expand All @@ -56,7 +62,6 @@ def _compute_can_be_created(self):
len(rec.product_tmpl_id.attribute_line_ids.mapped("attribute_id"))
- len(list(filter(None, rec.product_attribute_ids.mapped("value_id"))))
)
rec.price_extra = sum(rec.mapped("product_attribute_ids.price_extra"))

@api.depends("product_tmpl_id", "product_attribute_ids")
def _compute_product_id_configurator_domain(self):
Expand Down Expand Up @@ -104,7 +109,6 @@ def _empty_attributes(self):
def _onchange_product_tmpl_id_configurator(self):
self.ensure_one()
if not self.product_tmpl_id._origin:
self.product_id = False
self.product_id = False
self._empty_attributes()

Expand Down Expand Up @@ -147,15 +151,14 @@ def _onchange_product_attribute_ids_configurator(self):
if not self.product_id:
product_tmpl = self.product_tmpl_id
values = self.product_attribute_ids.mapped("value_id")
if "partner_id" in self._fields:
if self._partner_id_field in self._fields:
partner = self[self._partner_id_field]
# If our model has a partner_id field, language is got from it
obj = self.env["product.attribute.value"].with_context(
lang=self.partner_id.lang
lang=partner.lang
)
values = obj.browse(self.product_attribute_ids.mapped("value_id").ids)
obj = self.env["product.template"].with_context(
lang=self.partner_id.lang
)
obj = self.env["product.template"].with_context(lang=partner.lang)
product_tmpl = obj.browse(self.product_tmpl_id.id)
if "name" in self._fields:
self.name = self._get_product_description(product_tmpl, False, values)
Expand All @@ -165,11 +168,12 @@ def _onchange_product_id_configurator(self):
self.ensure_one()
if self.product_id:
product = self.product_id
if "partner_id" in self._fields:
if self._partner_id_field in self._fields:
partner = self[self._partner_id_field]
# If our model has a partner_id field, language is got from it
product = (
self.env["product.product"]
.with_context(lang=self.partner_id.lang)
.with_context(lang=partner.lang)
.browse(self.product_id.id)
)
if "name" in self._fields:
Expand Down
19 changes: 16 additions & 3 deletions product_variant_sale_price/models/product_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from odoo import api, fields, models
from odoo.tools import config


class ProductTemplate(models.Model):
Expand Down Expand Up @@ -44,7 +45,12 @@ def _get_combination_info(
parent_combination,
only_template,
)
res["price_extra"] = 0.0
test_condition = not config["test_enable"] or (
config["test_enable"]
and self.env.context.get("test_product_variant_sale_price")
)
if test_condition:
res["price_extra"] = 0.0
return res


Expand Down Expand Up @@ -104,5 +110,12 @@ def _compute_product_price_extra(self):
"""the sale.order.line module calculates the price_unit by adding
the value of price_extra and this can generate inconsistencies
if the field has old data stored."""
for product in self:
product.price_extra = 0.0
super()._compute_product_price_extra()
test_condition = not config["test_enable"] or (
config["test_enable"]
and self.env.context.get("test_product_variant_sale_price")
)
if test_condition:
for product in self:
product.price_extra = 0.0
return
3 changes: 3 additions & 0 deletions product_variant_sale_price/tests/test_product_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ class TestProductVariantPrice(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.env = cls.env(
context=dict(cls.env.context, test_test_product_variant_sale_price=True)
)
cls.template = cls.env["product.template"]
cls.product_product = cls.env["product.product"]
cls.attribute = cls.env["product.attribute"]
Expand Down
52 changes: 52 additions & 0 deletions sale_variant_configurator/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3

=======================
Sale - Product variants
=======================

This module allows you to create the product variant when a sale order is
confirmed. It adds to the sale line a product configurator, so that selecting
a product and its attributes can serve for creating/selecting the product
variant.

Usage
=====

.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/137/11.0

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

Bugs are tracked on `GitHub Issues
<https://github.com/OCA/product-variant/issues>`_. In case of trouble, please
check there if your issue has already been reported. If you spotted it first,
help us smash it by providing detailed and welcomed feedback.

Credits
=======

Contributors
------------
* Oihane Crucelaegui <[email protected]>
* Pedro M. Baeza <[email protected]>
* Ana Juaristi <[email protected]>
* David Vidal <[email protected]>

Maintainer
----------

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

This module is maintained by the OCA.

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.

To contribute to this module, please visit https://odoo-community.org.
4 changes: 4 additions & 0 deletions sale_variant_configurator/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from . import models
from .hooks import assign_product_template
23 changes: 23 additions & 0 deletions sale_variant_configurator/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2014-2016 Oihane Crucelaegui - AvanzOSC
# Copyright 2017 David Vidal <[email protected]>
# Copyright 2015-2021 Tecnativa - Pedro M. Baeza
# Copyright 2024 Tecnativa - Carolina Fernandez
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

{
"name": "Sale - Product variants",
"summary": "Product variants in sale management",
"version": "16.0.1.0.0",
"development_status": "Production/Stable",
"license": "AGPL-3",
"depends": ["sale", "product_variant_configurator"],
"author": "OdooMRP team,"
"AvanzOSC,"
"Tecnativa,"
"Odoo Community Association (OCA)",
"category": "Sales Management",
"website": "https://github.com/OCA/product-variant",
"data": ["views/sale_view.xml"],
"installable": True,
"post_init_hook": "assign_product_template",
}
13 changes: 13 additions & 0 deletions sale_variant_configurator/hooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# © 2014-2016 Oihane Crucelaegui - AvanzOSC
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html


def assign_product_template(cr, registry):
"""This post-init-hook will update all existing sale.order.line"""
cr.execute(
"""
UPDATE sale_order_line AS line
SET product_tmpl_id = product_product.product_tmpl_id
FROM product_product
WHERE line.product_id = product_product.id;"""
)
61 changes: 61 additions & 0 deletions sale_variant_configurator/i18n/ca.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * sale_variant_configurator
#
# Translators:
# OCA Transbot <[email protected]>, 2017
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 11.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-12-04 12:43+0000\n"
"PO-Revision-Date: 2017-12-04 12:43+0000\n"
"Last-Translator: OCA Transbot <[email protected]>, 2017\n"
"Language-Team: Catalan (https://www.transifex.com/oca/teams/23907/ca/)\n"
"Language: ca\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"

#. module: sale_variant_configurator
#: model:ir.model.constraint,message:sale_variant_configurator.constraint_sale_order_line_non_accountable_null_fields
msgid "Forbidden values on non-accountable sale order line"
msgstr ""

#. module: sale_variant_configurator
#: model:ir.model.constraint,message:sale_variant_configurator.constraint_sale_order_line_accountable_required_fields
msgid "Missing required fields on accountable sale order line."
msgstr ""

#. module: sale_variant_configurator
#: model:ir.model.fields,field_description:sale_variant_configurator.field_sale_order_line__product_id
msgid "Product"
msgstr ""

#. module: sale_variant_configurator
#: model_terms:ir.ui.view,arch_db:sale_variant_configurator.view_order_form
#: model_terms:ir.ui.view,arch_db:sale_variant_configurator.view_order_line_tree
#: model_terms:ir.ui.view,arch_db:sale_variant_configurator.view_sales_order_line_filter
msgid "Product Template"
msgstr "Plantilla del producte"

#. module: sale_variant_configurator
#: model:ir.model.fields,field_description:sale_variant_configurator.field_sale_order_line__product_tmpl_id
msgid "Product Template (no related)"
msgstr ""

#. module: sale_variant_configurator
#: model:ir.model,name:sale_variant_configurator.model_sale_order
msgid "Sales Order"
msgstr ""

#. module: sale_variant_configurator
#: model:ir.model,name:sale_variant_configurator.model_sale_order_line
msgid "Sales Order Line"
msgstr "Línia de comanda de vendes"

#. module: sale_variant_configurator
#: model_terms:ir.ui.view,arch_db:sale_variant_configurator.view_sales_order_line_filter
msgid "Template"
msgstr "Plantilla"
61 changes: 61 additions & 0 deletions sale_variant_configurator/i18n/de.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * sale_variant_configurator
#
# Translators:
# OCA Transbot <[email protected]>, 2017
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 11.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-12-04 12:43+0000\n"
"PO-Revision-Date: 2017-12-04 12:43+0000\n"
"Last-Translator: OCA Transbot <[email protected]>, 2017\n"
"Language-Team: German (https://www.transifex.com/oca/teams/23907/de/)\n"
"Language: de\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"

#. module: sale_variant_configurator
#: model:ir.model.constraint,message:sale_variant_configurator.constraint_sale_order_line_non_accountable_null_fields
msgid "Forbidden values on non-accountable sale order line"
msgstr ""

#. module: sale_variant_configurator
#: model:ir.model.constraint,message:sale_variant_configurator.constraint_sale_order_line_accountable_required_fields
msgid "Missing required fields on accountable sale order line."
msgstr ""

#. module: sale_variant_configurator
#: model:ir.model.fields,field_description:sale_variant_configurator.field_sale_order_line__product_id
msgid "Product"
msgstr ""

#. module: sale_variant_configurator
#: model_terms:ir.ui.view,arch_db:sale_variant_configurator.view_order_form
#: model_terms:ir.ui.view,arch_db:sale_variant_configurator.view_order_line_tree
#: model_terms:ir.ui.view,arch_db:sale_variant_configurator.view_sales_order_line_filter
msgid "Product Template"
msgstr "Produktvorlage"

#. module: sale_variant_configurator
#: model:ir.model.fields,field_description:sale_variant_configurator.field_sale_order_line__product_tmpl_id
msgid "Product Template (no related)"
msgstr ""

#. module: sale_variant_configurator
#: model:ir.model,name:sale_variant_configurator.model_sale_order
msgid "Sales Order"
msgstr ""

#. module: sale_variant_configurator
#: model:ir.model,name:sale_variant_configurator.model_sale_order_line
msgid "Sales Order Line"
msgstr "Auftragsposition"

#. module: sale_variant_configurator
#: model_terms:ir.ui.view,arch_db:sale_variant_configurator.view_sales_order_line_filter
msgid "Template"
msgstr "Vorlage"
Loading

0 comments on commit e128707

Please sign in to comment.