Skip to content

Commit

Permalink
[MIG] purchase_variant_configurator_on_confirm: Migration to 16.0
Browse files Browse the repository at this point in the history
TT46597
  • Loading branch information
victoralmau committed Jun 26, 2024
1 parent b7bbaad commit 91b45e3
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 66 deletions.
10 changes: 5 additions & 5 deletions purchase_variant_configurator_on_confirm/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ Purchase Variant Configurator On Confirm
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fproduct--variant-lightgray.png?logo=github
:target: https://github.com/OCA/product-variant/tree/13.0/purchase_variant_configurator_on_confirm
:target: https://github.com/OCA/product-variant/tree/16.0/purchase_variant_configurator_on_confirm
:alt: OCA/product-variant
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/product-variant-13-0/product-variant-13-0-purchase_variant_configurator_on_confirm
:target: https://translation.odoo-community.org/projects/product-variant-16-0/product-variant-16-0-purchase_variant_configurator_on_confirm
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/product-variant&target_branch=13.0
:target: https://runboat.odoo-community.org/builds?repo=OCA/product-variant&target_branch=16.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand All @@ -41,7 +41,7 @@ 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 to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/product-variant/issues/new?body=module:%20purchase_variant_configurator_on_confirm%0Aversion:%2013.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/product-variant/issues/new?body=module:%20purchase_variant_configurator_on_confirm%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.

Expand Down Expand Up @@ -82,6 +82,6 @@ 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/product-variant <https://github.com/OCA/product-variant/tree/13.0/purchase_variant_configurator_on_confirm>`_ project on GitHub.
This module is part of the `OCA/product-variant <https://github.com/OCA/product-variant/tree/16.0/purchase_variant_configurator_on_confirm>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
5 changes: 2 additions & 3 deletions purchase_variant_configurator_on_confirm/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Purchase Variant Configurator On Confirm",
"summary": """
Create product variants when confirming the purchase order""",
"version": "13.0.1.0.0",
"summary": "Create product variants when confirming the purchase order",
"version": "16.0.1.0.0",
"license": "AGPL-3",
"author": "AvanzOSC, "
"Tecnativa, "
Expand Down
40 changes: 21 additions & 19 deletions purchase_variant_configurator_on_confirm/models/purchase_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def _onchange_product_tmpl_id_configurator(self):
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 +74,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)
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 @@ -369,7 +368,7 @@ <h1 class="title">Purchase Variant Configurator On Confirm</h1>
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:c3e2e02c44ae9bde4f5da3f1235fc0708bd7ffd3fca00def779795f66484776f
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/product-variant/tree/13.0/purchase_variant_configurator_on_confirm"><img alt="OCA/product-variant" src="https://img.shields.io/badge/github-OCA%2Fproduct--variant-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/product-variant-13-0/product-variant-13-0-purchase_variant_configurator_on_confirm"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/product-variant&amp;target_branch=13.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/product-variant/tree/16.0/purchase_variant_configurator_on_confirm"><img alt="OCA/product-variant" src="https://img.shields.io/badge/github-OCA%2Fproduct--variant-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/product-variant-16-0/product-variant-16-0-purchase_variant_configurator_on_confirm"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/product-variant&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>Create product variants when confirming the purchase order.</p>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
Expand All @@ -388,7 +387,7 @@ <h1><a class="toc-backref" href="#toc-entry-1">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_on_confirm%0Aversion:%2013.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<a class="reference external" href="https://github.com/OCA/product-variant/issues/new?body=module:%20purchase_variant_configurator_on_confirm%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">
Expand Down Expand Up @@ -424,7 +423,7 @@ <h2><a class="toc-backref" href="#toc-entry-5">Maintainers</a></h2>
<p>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.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/product-variant/tree/13.0/purchase_variant_configurator_on_confirm">OCA/product-variant</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/product-variant/tree/16.0/purchase_variant_configurator_on_confirm">OCA/product-variant</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# Copyright 2017 Tecnativa - David Vidal
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
from odoo.tests import Form, common
from odoo.tests import Form

from odoo.addons.base.tests.common import BaseCommon

class TestPurchaseOrder(common.SavepointCase):

class TestPurchaseOrder(BaseCommon):
@classmethod
def setUpClass(cls):
super().setUpClass()
Expand Down Expand Up @@ -31,6 +33,7 @@ def setUpClass(cls):
{
"name": cls.template_name,
"no_create_variants": "yes",
"description_purchase": "Purchase Description",
"categ_id": cls.category1.id,
"standard_price": 100,
"attribute_line_ids": [
Expand All @@ -48,7 +51,7 @@ def setUpClass(cls):
cls.supplier_pricelist = cls.env["product.supplierinfo"].create(
{
"product_tmpl_id": cls.product_template_yes.id,
"name": cls.supplier.id,
"partner_id": cls.supplier.id,
"min_qty": 11,
"price": 90,
}
Expand All @@ -61,52 +64,57 @@ def setUpClass(cls):
"description_purchase": "Purchase Description",
}
)
cls.env.user.groups_id += cls.env.ref("uom.group_uom")
cls.order = cls.env["purchase.order"].create({"partner_id": cls.supplier.id})

def test_onchange_product_tmpl_id(self):
purchase = Form(self.order)
with purchase.order_line.new() as line:
line.product_tmpl_id = self.product_template_yes
self.assertEqual(line.name, self.template_name)
with purchase.order_line.new() as line_form:
line_form.product_tmpl_id = self.product_template_yes
purchase.save()
line = self.order.order_line
self.assertFalse(line.product_id)
self.assertIn(self.template_name, line.name)
self.assertIn("Purchase Description", line.name)
self.assertEqual(line.product_uom, self.product_template_yes.uom_id)
self.assertEqual(line.price_unit, 90)
self.assertEqual(line.product_qty, 11)
self.assertTrue(line.date_planned)
self.order.button_confirm()
self.assertTrue(line.product_id)
self.assertIn(self.template_name, line.name)
self.assertIn("Purchase Description", line.name)

def test_button_confirm(self):
line1 = self.env["purchase.order.line"].new(
{
"order_id": self.order.id,
"product_tmpl_id": self.product_template_yes.id,
}
)
line1._onchange_product_tmpl_id_configurator()
line1.product_attribute_ids[0].value_id = self.value1.id
line1 = line1.create(line1._convert_to_write(line1._cache))
purchase = Form(self.order)
with purchase.order_line.new() as line_form:
line_form.product_tmpl_id = self.product_template_yes
with line_form.product_attribute_ids.edit(0) as pa_form:
pa_form.value_id = self.value1
purchase.save()
line1 = self.order.order_line
self.assertFalse(line1.product_id)
self.order.button_confirm()
self.assertTrue(line1.product_id)
line2 = self.env["purchase.order.line"].new(
{
"order_id": self.order.id,
"product_tmpl_id": self.product_template_yes.id,
}
)
line2._onchange_product_tmpl_id_configurator()
line2.product_attribute_ids[0].value_id = self.value1.id
line2 = line2.create(line2._convert_to_write(line2._cache))
purchase = Form(self.order)
with purchase.order_line.new() as line_form:
line_form.product_tmpl_id = self.product_template_yes
with line_form.product_attribute_ids.edit(0) as pa_form:
pa_form.value_id = self.value2
purchase.save()
line2 = self.order.order_line - line1
self.assertTrue(line2.product_id)
self.assertNotEqual(line1.product_id, line2.product_id)

def test_copy(self):
line1 = self.env["purchase.order.line"].new(
{
"order_id": self.order.id,
"product_tmpl_id": self.product_template_yes.id,
}
)
line1._onchange_product_tmpl_id_configurator()
line1.product_attribute_ids[0].value_id = self.value1.id
purchase = Form(self.order)
old_date = "2017-01-01"
with purchase.order_line.new() as line_form:
line_form.product_tmpl_id = self.product_template_yes
line_form.date_planned = old_date
with line_form.product_attribute_ids.edit(0) as pa_form:
pa_form.value_id = self.value1
purchase.save()
old_date = "2017-01-01"
line1.date_planned = old_date
line1.create(line1._convert_to_write(line1._cache))
new_order = self.order.copy()
self.assertNotEqual(new_order.order_line.date_planned, old_date)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<record model="ir.ui.view" id="purchase_order_extended_form_view">
<record id="purchase_order_extended_form_view" model="ir.ui.view">
<field name="name">purchase.order.extended.form</field>
<field name="model">purchase.order</field>
<field name="inherit_id" ref="purchase.purchase_order_form" />
Expand Down

0 comments on commit 91b45e3

Please sign in to comment.