Skip to content

Commit

Permalink
[MIG] sale_elaboration: Migration to 14.0
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlosRoca13 committed Sep 30, 2022
1 parent c665eb8 commit 72ba394
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 81 deletions.
13 changes: 7 additions & 6 deletions sale_elaboration/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ Sale Elaboration
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsale--workflow-lightgray.png?logo=github
:target: https://github.com/OCA/sale-workflow/tree/13.0/sale_elaboration
:target: https://github.com/OCA/sale-workflow/tree/14.0/sale_elaboration
:alt: OCA/sale-workflow
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/sale-workflow-13-0/sale-workflow-13-0-sale_elaboration
:target: https://translation.odoo-community.org/projects/sale-workflow-14-0/sale-workflow-14-0-sale_elaboration
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/167/13.0
:target: https://runbot.odoo-community.org/runbot/167/14.0
:alt: Try me on Runbot

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand All @@ -43,7 +43,7 @@ Configuration

To configure this module you need to:

#. Go to *Sale > Configuration > Products > Elaboration Sale*.
#. Go to *Sale > Configuration > Products > Sale Elaboration*.
#. Create a new record.
#. Set a product linked to the elaboration.

Expand All @@ -65,7 +65,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/sale-workflow/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/sale-workflow/issues/new?body=module:%20sale_elaboration%0Aversion:%2013.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/sale-workflow/issues/new?body=module:%20sale_elaboration%0Aversion:%2014.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 All @@ -84,6 +84,7 @@ Contributors

* Sergio Teruel
* Pedro M. Baeza
* Carlos Roca

Maintainers
~~~~~~~~~~~
Expand All @@ -98,6 +99,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/sale-workflow <https://github.com/OCA/sale-workflow/tree/13.0/sale_elaboration>`_ project on GitHub.
This module is part of the `OCA/sale-workflow <https://github.com/OCA/sale-workflow/tree/14.0/sale_elaboration>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 1 addition & 1 deletion sale_elaboration/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{
"name": "Sale Elaboration",
"summary": "Set an elaboration for any sale line",
"version": "13.0.1.1.0",
"version": "14.0.1.0.0",
"development_status": "Production/Stable",
"category": "Sale",
"website": "https://github.com/OCA/sale-workflow",
Expand Down
9 changes: 2 additions & 7 deletions sale_elaboration/models/product_elaboration.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,10 @@ def name_search(self, name, args=None, operator="ilike", limit=100):
"""Give preference to codes on name search, appending
the rest of the results after.
"""
if not args:
args = []
args = args or []
recs = self.search([("code", operator, name)] + args, limit=limit)
res = recs.name_get()
if limit:
limit_rest = limit - len(recs)
else: # pragma: no cover
# limit can be 0 or None representing infinite
limit_rest = limit
limit_rest = limit - len(recs) if limit else limit
if limit_rest or not limit:
args += [("id", "not in", recs.ids)]
res += super().name_search(
Expand Down
8 changes: 6 additions & 2 deletions sale_elaboration/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,17 @@ def _compute_elaboration_note(self):
for line in self:
line.elaboration_note = line.elaboration_id.name

def _prepare_invoice_line(self):
vals = super()._prepare_invoice_line()
def _prepare_invoice_line(self, **optional_values):
vals = super()._prepare_invoice_line(**optional_values)
if self.is_elaboration:
vals["name"] = "{} - {}".format(self.order_id.name, self.name)
return vals

@api.depends("product_id")
def _compute_is_elaboration(self):
"""We use computed instead of a related field because related fields are not
initialized with their value on one2many which related field is the
inverse_name, so with this we get immediately the value on NewIds.
"""
for line in self:
line.is_elaboration = line.product_id.is_elaboration
4 changes: 2 additions & 2 deletions sale_elaboration/models/stock_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
class StockPicking(models.Model):
_inherit = "stock.picking"

def action_done(self):
res = super(StockPicking, self).action_done()
def _action_done(self):
res = super()._action_done()
for pick in self.filtered(lambda x: x.picking_type_code == "outgoing"):
elaboration_lines = pick.move_lines.filtered(
lambda x: x.sale_line_id.elaboration_id
Expand Down
2 changes: 1 addition & 1 deletion sale_elaboration/readme/CONFIGURE.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
To configure this module you need to:

#. Go to *Sale > Configuration > Products > Elaboration Sale*.
#. Go to *Sale > Configuration > Products > Sale Elaboration*.
#. Create a new record.
#. Set a product linked to the elaboration.
1 change: 1 addition & 0 deletions sale_elaboration/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@

* Sergio Teruel
* Pedro M. Baeza
* Carlos Roca
11 changes: 6 additions & 5 deletions sale_elaboration/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils 0.15.1: http://docutils.sourceforge.net/" />
<meta name="generator" content="Docutils: http://docutils.sourceforge.net/" />
<title>Sale Elaboration</title>
<style type="text/css">

Expand Down Expand Up @@ -367,7 +367,7 @@ <h1 class="title">Sale Elaboration</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Production/Stable" src="https://img.shields.io/badge/maturity-Production%2FStable-green.png" /></a> <a class="reference external" 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" href="https://github.com/OCA/sale-workflow/tree/13.0/sale_elaboration"><img alt="OCA/sale-workflow" src="https://img.shields.io/badge/github-OCA%2Fsale--workflow-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/sale-workflow-13-0/sale-workflow-13-0-sale_elaboration"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/167/13.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Production/Stable" src="https://img.shields.io/badge/maturity-Production%2FStable-green.png" /></a> <a class="reference external" 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" href="https://github.com/OCA/sale-workflow/tree/14.0/sale_elaboration"><img alt="OCA/sale-workflow" src="https://img.shields.io/badge/github-OCA%2Fsale--workflow-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/sale-workflow-14-0/sale-workflow-14-0-sale_elaboration"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/167/14.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p>This module extends the functionality of sales orders to allow to set an
elaboration on lines that will add an extra order line with an elaboration
product linked to it when the delivery order is validated.</p>
Expand All @@ -392,7 +392,7 @@ <h1 class="title">Sale Elaboration</h1>
<h1><a class="toc-backref" href="#id1">Configuration</a></h1>
<p>To configure this module you need to:</p>
<ol class="arabic simple">
<li>Go to <em>Sale &gt; Configuration &gt; Products &gt; Elaboration Sale</em>.</li>
<li>Go to <em>Sale &gt; Configuration &gt; Products &gt; Sale Elaboration</em>.</li>
<li>Create a new record.</li>
<li>Set a product linked to the elaboration.</li>
</ol>
Expand All @@ -415,7 +415,7 @@ <h1><a class="toc-backref" href="#id3">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/sale-workflow/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 smashing it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/sale-workflow/issues/new?body=module:%20sale_elaboration%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/sale-workflow/issues/new?body=module:%20sale_elaboration%0Aversion:%2014.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 All @@ -432,6 +432,7 @@ <h2><a class="toc-backref" href="#id6">Contributors</a></h2>
<li><a class="reference external" href="https://www.tecnativa.com">Tecnativa</a>:<ul>
<li>Sergio Teruel</li>
<li>Pedro M. Baeza</li>
<li>Carlos Roca</li>
</ul>
</li>
</ul>
Expand All @@ -443,7 +444,7 @@ <h2><a class="toc-backref" href="#id7">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/sale-workflow/tree/13.0/sale_elaboration">OCA/sale-workflow</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/sale-workflow/tree/14.0/sale_elaboration">OCA/sale-workflow</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
80 changes: 24 additions & 56 deletions sale_elaboration/tests/test_sale_elaboration.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Copyright 2018 Tecnativa - Sergio Teruel
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo.tests import SavepointCase, tagged
from odoo.tests import Form, SavepointCase, tagged


@tagged("post_install", "-at_install")
Expand All @@ -10,7 +10,7 @@ def setUpClass(cls):
super().setUpClass()
cls.Elaboration = cls.env["product.elaboration"]
cls.product = cls.env["product.product"].create(
{"name": "test", "tracking": "none"}
{"name": "test", "tracking": "none", "list_price": 1000}
)
cls.product_elaboration_A = cls.env["product.product"].create(
{
Expand Down Expand Up @@ -63,28 +63,18 @@ def setUpClass(cls):
"product_id": cls.product_elaboration_B.id,
}
)
so = cls.env["sale.order"].new(
{
"partner_id": cls.partner.id,
"order_line": [
(
0,
0,
{
"name": cls.product.name,
"product_id": cls.product.id,
"product_uom_qty": 10.0,
"product_uom": cls.product.uom_id.id,
"price_unit": 1000.00,
"elaboration_id": cls.elaboration_a.id,
"elaboration_note": "elaboration A",
},
)
],
}
)
so.onchange_partner_id()
cls.order = cls.env["sale.order"].create(so._convert_to_write(so._cache))
cls.order = cls._create_sale_order(cls, [(cls.product, 10, cls.elaboration_a)])

def _create_sale_order(self, products_info):
order_form = Form(self.env["sale.order"])
order_form.partner_id = self.partner
for product, qty, elaboration in products_info:
with order_form.order_line.new() as line_form:
line_form.product_id = product
line_form.product_uom_qty = qty
if elaboration:
line_form.elaboration_id = elaboration
return order_form.save()

def test_search_elaboration(self):
elaboration = self.Elaboration.name_search("Elaboration")
Expand All @@ -99,7 +89,7 @@ def test_sale_elaboration_change(self):
def test_sale_elaboration(self):
self.order.action_confirm()
self.order.picking_ids.move_lines.quantity_done = 10.0
self.order.picking_ids.action_done()
self.order.picking_ids._action_done()
elaboration_lines = self.order.order_line.filtered("is_elaboration")
self.assertEqual(len(elaboration_lines), 1)
self.assertEqual(elaboration_lines.price_unit, 50.0)
Expand All @@ -116,43 +106,21 @@ def test_sale_elaboration_multi(self):
)
self.order.action_confirm()
self.order.picking_ids.move_lines.quantity_done = 10.0
self.order.picking_ids.action_done()
self.order.picking_ids._action_done()
elaboration_lines = self.order.order_line.filtered("is_elaboration")
self.assertEqual(len(elaboration_lines), 1)
self.assertEqual(elaboration_lines.product_uom_qty, 11.0)

def test_invoice_elaboration(self):
so = self.env["sale.order"].new(
{
"partner_id": self.partner.id,
"order_line": [
(
0,
0,
{
"name": self.product_elaboration_A.name,
"product_id": self.product_elaboration_A.id,
"product_uom_qty": 1.0,
"price_unit": 50.0,
"is_elaboration": True,
},
),
(
0,
0,
{
"name": self.product_elaboration_B.name,
"product_id": self.product_elaboration_B.id,
"product_uom_qty": 1.0,
"price_unit": 50.0,
"is_elaboration": False,
},
),
],
}
self.order = self._create_sale_order(
[
(self.product_elaboration_A, 1, False),
(self.product_elaboration_B, 1, False),
]
)
so.onchange_partner_id()
self.order = self.env["sale.order"].create(so._convert_to_write(so._cache))
self.order.order_line.filtered(
lambda l: l.product_id == self.product_elaboration_B
).is_elaboration = False
self.order.action_confirm()
invoice = self.order._create_invoices()
so_line_elaboration = self.order.order_line.filtered("is_elaboration")
Expand Down
8 changes: 7 additions & 1 deletion sale_elaboration/views/sale_elaboration_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@
<field name="arch" type="xml">
<form string="Elaborations">
<sheet>
<widget
name="web_ribbon"
title="Archived"
bg_color="bg-danger"
attrs="{'invisible': [('active', '=', True)]}"
/>
<field name="active" invisible="1" />
<group>
<field name="code" />
<field name="name" />
Expand All @@ -31,7 +38,6 @@
name="product_id"
context="{'default_is_elaboration': True, 'default_type': 'service'}"
/>
<field name="active" invisible="1" />
</tree>
</field>
</record>
Expand Down

0 comments on commit 72ba394

Please sign in to comment.