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] sale_variant_configurator: Migration to version 16.0 #353

Merged
merged 21 commits into from
Jun 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
a893f2f
sale_variant_configurator: Migration to 9.0
pedrobaeza Dec 7, 2016
e1f83d8
[MIG] sale_variant_configurator: Migration to 10.0
chienandalu Jul 6, 2017
1a6f79f
[IMP] sale_variant_configurator: Avoid warning on non existing field
pedrobaeza Dec 4, 2017
0a447e4
[FIX] sale_variant_configurator: Don't choke on attribute name
pedrobaeza Dec 22, 2017
9f98399
[UPD] Update sale_variant_configurator.pot
oca-travis Jun 23, 2018
86c4c9e
[MIG] sale_variant_configurator: Migration to 11.0
angelmoya Sep 17, 2018
a0af7b9
[FIX] sale_variant_configurator: typo, field does not exist
cubells Oct 25, 2018
da24b61
[FIX] *_variant_configurator: don't lose attribute on save
pedrobaeza Nov 29, 2018
4ec4f6a
[FIX] sale_variant_configurator: attribute lines are not created
cubells Dec 5, 2018
48df1c7
[11.0][FIX] Filter products according to the view
SalahAdDin Dec 12, 2018
286b5e4
[FIX] sale_variant_configurator: Proper SO line description
pedrobaeza Jan 30, 2019
6319f5f
[FIX] sale_variant_configurator: Don't lose sales description
pedrobaeza Jan 30, 2019
d5a32ba
[FIX+IMP] sale_variant_configurator: Variant creation when confirmed
pedrobaeza Feb 1, 2019
2fecc32
[FIX] sale_variant_configurator: Return value in action_confirm
pedrobaeza Feb 26, 2019
abd4c10
[ADD] icon.png
OCA-git-bot Apr 3, 2019
080a9bc
[FIX] broken test in sale_variant_configurator
gurneyalex Feb 10, 2020
2bfb9c9
"[IMP] sale_variant_configurator: black, isort, prettier"
chienandalu Jan 25, 2021
0c804bf
[MIG] sale_variant_configurator: Migration to 13.0
chienandalu Jan 27, 2021
b77f883
[FIX] sale_variant_configurator: Populate product description in cust…
pedrobaeza Nov 18, 2021
2b98329
[IMP] sale_variant_configurator: pre-commit stuff
carolinafernandez-tecnativa Jan 16, 2024
2351a7b
[MIG] sale_variant_configurator: Migration to version 16.0
carolinafernandez-tecnativa Jan 17, 2024
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
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:
pedrobaeza marked this conversation as resolved.
Show resolved Hide resolved
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)
)
self.name = self._get_product_description(
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 (
pedrobaeza marked this conversation as resolved.
Show resolved Hide resolved
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
Loading