Skip to content

Commit

Permalink
[MIG] purchase_variant_configurator_on_confirm: Merged into purchase_…
Browse files Browse the repository at this point in the history
…variant_configurator and migration to 16.0

TT46597
  • Loading branch information
victoralmau committed Jun 28, 2024
1 parent b7bbaad commit e1d6c4e
Show file tree
Hide file tree
Showing 49 changed files with 279 additions and 1,856 deletions.
31 changes: 31 additions & 0 deletions purchase_variant_configurator/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,37 @@ selecting a product and its attributes can be created a new product variant.
.. contents::
:local:

Configuration
=============

#. Go to ``Purchase > Configuration > Settings``.
#. Check the "Create variants on confirm" option if you want to delay the creation
of them until the order confirmation.

Usage
=====

#. Go to a purchase order or create a new one.
#. Create a new line
#. Set in Product Template some product with attributes and variants.
#. All product attributes will be displayed in table mode just below.
#. Set a value for all attributes.
#. A product variant (with the selected options) will be auto-set.


Only if the "Create variants on confirm" option in the configuration is set.


#. Go to ``Purchase > Products > Product`` and create a new one.
#. Go to the "Attributes & Variants" tab.
#. Set in "Variant creation" the option "Do not create them automatically".
#. Set some attribute and value(s)
#. Go to a purchase order or create a new one.
#. Create a new line
#. Set in Product Template the one created before and select values for attributes.
#. Confirm orden.
#. A product variant (with the selected options) will have been created for the Product Template.

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

Expand Down
5 changes: 4 additions & 1 deletion purchase_variant_configurator/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
"Odoo Community Association (OCA)",
"category": "Purchase Management",
"website": "https://github.com/OCA/product-variant",
"data": ["views/inherited_purchase_order_views.xml"],
"data": [
"views/inherited_purchase_order_views.xml",
"views/res_config_settings_views.xml",
],
"installable": True,
"post_init_hook": "assign_product_template",
}
7 changes: 6 additions & 1 deletion purchase_variant_configurator/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
from . import purchase_order_line
from . import product_product
from . import product_supplierinfo
from . import product_template
from . import purchase_order
from . import res_company
from . import res_config_settings
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright 2016 Oihane Crucelaegui - AvanzOSC
# Copyright 2016-2017 Tecnativa - Pedro M. Baeza
# Copyright 2016 ACSONE SA/NV
# Copyright 2017 Tecnativa - David Vidal
# Copyright 2016-2017 Tecnativa - Pedro M. Baeza
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from odoo import api, fields, models
Expand Down Expand Up @@ -39,6 +39,7 @@ class PurchaseOrderLine(models.Model):
_name = "purchase.order.line"

product_id = fields.Many2one(required=False)
product_id_is_required = fields.Boolean(compute="_compute_product_id_is_required")

_sql_constraints = [
(
Expand All @@ -57,13 +58,18 @@ class PurchaseOrderLine(models.Model):
),
]

@api.depends("company_id")
def _compute_product_id_is_required(self):
for item in self:
item.product_id_is_required = not item.company_id.po_confirm_create_variant

@api.onchange("product_tmpl_id")
def _onchange_product_tmpl_id_configurator(self):
"""Make use of PurchaseOrderLine onchange_product_id method with
a virtual product created on the fly.
"""
res = super()._onchange_product_tmpl_id_configurator()
if not self.product_id:
if not self.product_id and self.product_tmpl_id:
self.product_id = self.product_tmpl_id._product_from_tmpl()
# HACK: With NewId, the `search` method that looks for vendor pricelists
# related to the product is unable to find the linked template as the
Expand All @@ -74,26 +80,28 @@ def _onchange_product_tmpl_id_configurator(self):
self.with_context(
pvc_product_tmpl=self.product_tmpl_id.id
).onchange_product_id()
self.product_id = False
# HACK: With NewId, making `with_context` loses temp values, so we
# need to recreate these operations
product_lang = self.product_tmpl_id.with_context(
{"lang": self.partner_id.lang, "partner_id": self.partner_id.id}
)
self.name = product_lang.display_name
if product_lang.description_purchase:
self.name += "\n" + product_lang.description_purchase
return res

def create(self, vals):
@api.model
def _get_product_description(self, template, product, product_attributes):
"""Add description_purchase to name field (similar to what purchase does)."""
name = super()._get_product_description(
template=template, product=product, product_attributes=product_attributes
)
if template.description_purchase:
name += "\n" + template.description_purchase
return name

@api.model_create_multi
def create(self, vals_list):
"""Create variant before calling super when the purchase order is
confirmed, as it creates associated stock moves.
"""
if "order_id" not in vals or vals.get("product_id"):
return super().create(vals)
order = self.env["purchase.order"].browse(vals["order_id"])
if order.state == "purchase":
line = self.new(vals)
product = line.create_variant_if_needed()
vals["product_id"] = product.id
return super().create(vals)
for vals in vals_list:
if vals.get("order_id") and not vals.get("product_id"):
order = self.env["purchase.order"].browse(vals["order_id"])
if order.state == "purchase":
line = self.new(vals)
product = line.create_variant_if_needed()
vals["product_id"] = product.id
return super().create(vals_list)
11 changes: 0 additions & 11 deletions purchase_variant_configurator/models/purchase_order_line.py

This file was deleted.

14 changes: 14 additions & 0 deletions purchase_variant_configurator/models/res_company.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright 2024 Tecnativa - Víctor Martínez
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models


class ResCompany(models.Model):
_inherit = "res.company"

po_confirm_create_variant = fields.Boolean(
string="Create variants on confirm",
help="Create product variants when confirming",
default=False,
)
12 changes: 12 additions & 0 deletions purchase_variant_configurator/models/res_config_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright 2024 Tecnativa - Víctor Martínez
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from odoo import fields, models


class ResConfigSettings(models.TransientModel):
_inherit = "res.config.settings"

po_confirm_create_variant = fields.Boolean(
related="company_id.po_confirm_create_variant", readonly=False
)
3 changes: 3 additions & 0 deletions purchase_variant_configurator/readme/CONFIGURE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#. Go to ``Purchase > Configuration > Settings``.
#. Check the "Create variants on confirm" option if you want to delay the creation
of them until the order confirmation.
20 changes: 20 additions & 0 deletions purchase_variant_configurator/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#. Go to a purchase order or create a new one.
#. Create a new line
#. Set in Product Template some product with attributes and variants.
#. All product attributes will be displayed in table mode just below.
#. Set a value for all attributes.
#. A product variant (with the selected options) will be auto-set.


Only if the "Create variants on confirm" option in the configuration is set.


#. Go to ``Purchase > Products > Product`` and create a new one.
#. Go to the "Attributes & Variants" tab.
#. Set in "Variant creation" the option "Do not create them automatically".
#. Set some attribute and value(s)
#. Go to a purchase order or create a new one.
#. Create a new line
#. Set in Product Template the one created before and select values for attributes.
#. Confirm orden.
#. A product variant (with the selected options) will have been created for the Product Template.
54 changes: 43 additions & 11 deletions purchase_variant_configurator/static/description/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
Expand Down Expand Up @@ -376,35 +375,68 @@ <h1 class="title">Purchase - Product variants</h1>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
<ul class="simple">
<li><a class="reference internal" href="#bug-tracker" id="toc-entry-1">Bug Tracker</a></li>
<li><a class="reference internal" href="#credits" id="toc-entry-2">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="toc-entry-3">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="toc-entry-4">Contributors</a></li>
<li><a class="reference internal" href="#maintainers" id="toc-entry-5">Maintainers</a></li>
<li><a class="reference internal" href="#configuration" id="toc-entry-1">Configuration</a></li>
<li><a class="reference internal" href="#usage" id="toc-entry-2">Usage</a></li>
<li><a class="reference internal" href="#bug-tracker" id="toc-entry-3">Bug Tracker</a></li>
<li><a class="reference internal" href="#credits" id="toc-entry-4">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="toc-entry-5">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="toc-entry-6">Contributors</a></li>
<li><a class="reference internal" href="#maintainers" id="toc-entry-7">Maintainers</a></li>
</ul>
</li>
</ul>
</div>
<div class="section" id="configuration">
<h1><a class="toc-backref" href="#toc-entry-1">Configuration</a></h1>
<ol class="arabic simple">
<li>Go to <tt class="docutils literal">Purchase &gt; Configuration &gt; Settings</tt>.</li>
<li>Check the “Create variants on confirm” option if you want to delay the creation
of them until the order confirmation.</li>
</ol>
</div>
<div class="section" id="usage">
<h1><a class="toc-backref" href="#toc-entry-2">Usage</a></h1>
<ol class="arabic simple">
<li>Go to a purchase order or create a new one.</li>
<li>Create a new line</li>
<li>Set in Product Template some product with attributes and variants.</li>
<li>All product attributes will be displayed in table mode just below.</li>
<li>Set a value for all attributes.</li>
<li>A product variant (with the selected options) will be auto-set.</li>
</ol>
<p>Only if the “Create variants on confirm” option in the configuration is set.</p>
<ol class="arabic simple">
<li>Go to <tt class="docutils literal">Purchase &gt; Products &gt; Product</tt> and create a new one.</li>
<li>Go to the “Attributes &amp; Variants” tab.</li>
<li>Set in “Variant creation” the option “Do not create them automatically”.</li>
<li>Set some attribute and value(s)</li>
<li>Go to a purchase order or create a new one.</li>
<li>Create a new line</li>
<li>Set in Product Template the one created before and select values for attributes.</li>
<li>Confirm orden.</li>
<li>A product variant (with the selected options) will have been created for the Product Template.</li>
</ol>
</div>
<div class="section" id="bug-tracker">
<h1><a class="toc-backref" href="#toc-entry-1">Bug Tracker</a></h1>
<h1><a class="toc-backref" href="#toc-entry-3">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/product-variant/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/product-variant/issues/new?body=module:%20purchase_variant_configurator%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
<h1><a class="toc-backref" href="#toc-entry-2">Credits</a></h1>
<h1><a class="toc-backref" href="#toc-entry-4">Credits</a></h1>
<div class="section" id="authors">
<h2><a class="toc-backref" href="#toc-entry-3">Authors</a></h2>
<h2><a class="toc-backref" href="#toc-entry-5">Authors</a></h2>
<ul class="simple">
<li>AvanzOSC</li>
<li>Tecnativa</li>
<li>ACSONE SA/NV</li>
</ul>
</div>
<div class="section" id="contributors">
<h2><a class="toc-backref" href="#toc-entry-4">Contributors</a></h2>
<h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
<ul class="simple">
<li>Oihane Crucelaegui &lt;<a class="reference external" href="mailto:oihanecrucelaegi&#64;avanzosc.es">oihanecrucelaegi&#64;avanzosc.es</a>&gt;</li>
<li>David Díaz &lt;<a class="reference external" href="mailto:d.diazp&#64;gmail.com">d.diazp&#64;gmail.com</a>&gt;</li>
Expand All @@ -418,7 +450,7 @@ <h2><a class="toc-backref" href="#toc-entry-4">Contributors</a></h2>
</ul>
</div>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-5">Maintainers</a></h2>
<h2><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
Expand Down
Loading

0 comments on commit e1d6c4e

Please sign in to comment.