Skip to content

Commit 2ae7790

Browse files
sergio-teruelCarlosRoca13
authored andcommitted
[IMP] sale_elaboration: Based report view elaborations in stock moves instead of sale.order.lines
TT51619
1 parent 05e392f commit 2ae7790

File tree

7 files changed

+126
-144
lines changed

7 files changed

+126
-144
lines changed

sale_elaboration/README.rst

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
.. image:: https://odoo-community.org/readme-banner-image
2-
:target: https://odoo-community.org/get-involved?utm_source=readme
3-
:alt: Odoo Community Association
4-
51
================
62
Sale Elaboration
73
================
@@ -17,7 +13,7 @@ Sale Elaboration
1713
.. |badge1| image:: https://img.shields.io/badge/maturity-Production%2FStable-green.png
1814
:target: https://odoo-community.org/page/development-status
1915
:alt: Production/Stable
20-
.. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png
16+
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
2117
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
2218
:alt: License: AGPL-3
2319
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsale--workflow-lightgray.png?logo=github

sale_elaboration/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"views/sale_elaboration_profile_views.xml",
2121
"views/sale_elaboration_views.xml",
2222
"views/sale_order_views.xml",
23-
"views/sale_elaboration_report_views.xml",
23+
"views/stock_move_report_views.xml",
2424
"views/stock_move_line_views.xml",
2525
"views/stock_picking_views.xml",
2626
"reports/report_base.xml",

sale_elaboration/models/sale_order.py

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# Copyright 2018 Tecnativa - Sergio Teruel
22
# Copyright 2019 Tecnativa - Pedro M. Baeza
33
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
4-
from odoo import _, api, fields, models
5-
from odoo.exceptions import UserError
4+
from odoo import api, fields, models
65

76

87
def _execute_onchanges(records, field_name):
@@ -54,11 +53,6 @@ class SaleOrderLine(models.Model):
5453
elaboration_price_unit = fields.Float(
5554
"Elab. Price", compute="_compute_elaboration_price_unit", store=True
5655
)
57-
is_prepared = fields.Boolean(
58-
compute=lambda self: None,
59-
search="_search_is_prepared",
60-
help=("Dummy field to be able to find prepared lines"),
61-
)
6256

6357
@api.depends("product_id")
6458
def _compute_elaboration_profile_id(self):
@@ -97,30 +91,3 @@ def _prepare_invoice_line(self, **optional_values):
9791
if self.is_elaboration:
9892
vals["name"] = f"{self.order_id.name} - {self.name}"
9993
return vals
100-
101-
def _search_is_prepared(self, operator, value):
102-
if operator != "=":
103-
raise UserError(
104-
_("Unsupported operator %s for searching on is_prepared") % (operator,)
105-
)
106-
moves = self.env["stock.move"].search(
107-
[
108-
(
109-
"state",
110-
"not in" if value else "in",
111-
[
112-
"draft",
113-
"waiting",
114-
"confirmed",
115-
"partially_available",
116-
"assigned",
117-
],
118-
),
119-
(
120-
"location_dest_id",
121-
"=",
122-
self.env.ref("stock.stock_location_customers").id,
123-
),
124-
]
125-
)
126-
return [("move_ids", "in", moves.ids)]

sale_elaboration/models/stock_move.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,26 @@ class StockMove(models.Model):
88
_inherit = ["stock.move", "product.elaboration.mixin"]
99
_name = "stock.move"
1010

11+
# Helper fields to display elaborations in tree view
12+
sale_id = fields.Many2one(
13+
comodel_name="sale.order", compute="_compute_sale_related_data"
14+
)
15+
salesman_id = fields.Many2one(
16+
comodel_name="res.users", compute="_compute_sale_related_data"
17+
)
18+
order_date = fields.Datetime(compute="_compute_sale_related_data")
19+
sequence_code = fields.Char(compute="_compute_sale_related_data")
20+
21+
def _compute_sale_related_data(self):
22+
# Get all chained moves to get sale line
23+
for move in self:
24+
moves = self.browse(list(self._rollup_move_dests({move.id})))
25+
move_sale = moves.filtered("sale_line_id")[:1]
26+
move.sale_id = move_sale.sale_line_id.order_id
27+
move.salesman_id = move_sale.sale_line_id.order_id.user_id
28+
move.order_date = move_sale.sale_line_id.date_order
29+
move.sequence_code = move.picking_type_id.sequence_code
30+
1131
@api.model
1232
def _prepare_merge_moves_distinct_fields(self):
1333
"""Don't merge moves with distinct elaborations"""

sale_elaboration/static/description/index.html

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<head>
44
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
55
<meta name="generator" content="Docutils: https://docutils.sourceforge.io/" />
6-
<title>README.rst</title>
6+
<title>Sale Elaboration</title>
77
<style type="text/css">
88

99
/*
@@ -360,21 +360,16 @@
360360
</style>
361361
</head>
362362
<body>
363-
<div class="document">
363+
<div class="document" id="sale-elaboration">
364+
<h1 class="title">Sale Elaboration</h1>
364365

365-
366-
<a class="reference external image-reference" href="https://odoo-community.org/get-involved?utm_source=readme">
367-
<img alt="Odoo Community Association" src="https://odoo-community.org/readme-banner-image" />
368-
</a>
369-
<div class="section" id="sale-elaboration">
370-
<h1>Sale Elaboration</h1>
371366
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
372367
!! This file is generated by oca-gen-addon-readme !!
373368
!! changes will be overwritten. !!
374369
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
375370
!! source digest: sha256:adeb8d361b6078141fbb5f50b50c5369061c8303bf88ba266a5e7a09527a59cf
376371
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
377-
<p><a class="reference external image-reference" 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 image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/license-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/sale-workflow/tree/18.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 image-reference" href="https://translation.odoo-community.org/projects/sale-workflow-18-0/sale-workflow-18-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 image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/sale-workflow&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
372+
<p><a class="reference external image-reference" 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 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/sale-workflow/tree/18.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 image-reference" href="https://translation.odoo-community.org/projects/sale-workflow-18-0/sale-workflow-18-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 image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/sale-workflow&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
378373
<p>This module extends the functionality of sales orders to allow to set an
379374
elaboration on lines that will add an extra order line with an
380375
elaboration product linked to it when the delivery order is validated.</p>
@@ -401,13 +396,13 @@ <h1>Sale Elaboration</h1>
401396
</ul>
402397
</div>
403398
<div class="section" id="use-cases-context">
404-
<h2><a class="toc-backref" href="#toc-entry-1">Use Cases / Context</a></h2>
399+
<h1><a class="toc-backref" href="#toc-entry-1">Use Cases / Context</a></h1>
405400
<p>This module was created to meet the need of providing the customer with
406401
products that are not transformed into something new, but rather require
407402
a simple preparation process. Example: Scaling a fish</p>
408403
</div>
409404
<div class="section" id="configuration">
410-
<h2><a class="toc-backref" href="#toc-entry-2">Configuration</a></h2>
405+
<h1><a class="toc-backref" href="#toc-entry-2">Configuration</a></h1>
411406
<p>To configure this module you need to:</p>
412407
<ol class="arabic simple">
413408
<li>Go to <em>Sale &gt; Configuration &gt; Elaborations &gt; Sale Elaboration</em>.</li>
@@ -439,7 +434,7 @@ <h2><a class="toc-backref" href="#toc-entry-2">Configuration</a></h2>
439434
</ol>
440435
</div>
441436
<div class="section" id="usage">
442-
<h2><a class="toc-backref" href="#toc-entry-3">Usage</a></h2>
437+
<h1><a class="toc-backref" href="#toc-entry-3">Usage</a></h1>
443438
<ol class="arabic simple">
444439
<li>Go to <em>Sale &gt; Quotations</em>.</li>
445440
<li>Create a sales order.</li>
@@ -455,23 +450,23 @@ <h2><a class="toc-backref" href="#toc-entry-3">Usage</a></h2>
455450
</ol>
456451
</div>
457452
<div class="section" id="bug-tracker">
458-
<h2><a class="toc-backref" href="#toc-entry-4">Bug Tracker</a></h2>
453+
<h1><a class="toc-backref" href="#toc-entry-4">Bug Tracker</a></h1>
459454
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/sale-workflow/issues">GitHub Issues</a>.
460455
In case of trouble, please check there if your issue has already been reported.
461456
If you spotted it first, help us to smash it by providing a detailed and welcomed
462457
<a class="reference external" href="https://github.com/OCA/sale-workflow/issues/new?body=module:%20sale_elaboration%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
463458
<p>Do not contact contributors directly about support or help with technical issues.</p>
464459
</div>
465460
<div class="section" id="credits">
466-
<h2><a class="toc-backref" href="#toc-entry-5">Credits</a></h2>
461+
<h1><a class="toc-backref" href="#toc-entry-5">Credits</a></h1>
467462
<div class="section" id="authors">
468-
<h3><a class="toc-backref" href="#toc-entry-6">Authors</a></h3>
463+
<h2><a class="toc-backref" href="#toc-entry-6">Authors</a></h2>
469464
<ul class="simple">
470465
<li>Tecnativa</li>
471466
</ul>
472467
</div>
473468
<div class="section" id="contributors">
474-
<h3><a class="toc-backref" href="#toc-entry-7">Contributors</a></h3>
469+
<h2><a class="toc-backref" href="#toc-entry-7">Contributors</a></h2>
475470
<ul class="simple">
476471
<li><a class="reference external" href="https://www.tecnativa.com">Tecnativa</a>:<ul>
477472
<li>Sergio Teruel</li>
@@ -485,7 +480,7 @@ <h3><a class="toc-backref" href="#toc-entry-7">Contributors</a></h3>
485480
</ul>
486481
</div>
487482
<div class="section" id="maintainers">
488-
<h3><a class="toc-backref" href="#toc-entry-8">Maintainers</a></h3>
483+
<h2><a class="toc-backref" href="#toc-entry-8">Maintainers</a></h2>
489484
<p>This module is maintained by the OCA.</p>
490485
<a class="reference external image-reference" href="https://odoo-community.org">
491486
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
@@ -500,6 +495,5 @@ <h3><a class="toc-backref" href="#toc-entry-8">Maintainers</a></h3>
500495
</div>
501496
</div>
502497
</div>
503-
</div>
504498
</body>
505499
</html>

sale_elaboration/views/sale_elaboration_report_views.xml

Lines changed: 0 additions & 86 deletions
This file was deleted.
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<!-- Copyright 2024 Tecnativa - Sergio Teruel
3+
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
4+
<odoo>
5+
<record id="report_stock_move_elaboration_view_tree" model="ir.ui.view">
6+
<field name="name">Elaborations</field>
7+
<field name="model">stock.move</field>
8+
<field name="arch" type="xml">
9+
<list create="false" default_order="date desc">
10+
<field name="sequence_code" />
11+
<field name="order_date" />
12+
<field name="date" widget="date" />
13+
<field name="date_deadline" optional="hide" />
14+
<field name="sale_id" />
15+
<field name="salesman_id" />
16+
<field name="partner_id" />
17+
<field name="product_id" />
18+
<field name="elaboration_ids" widget="many2many_tags" />
19+
<field name="elaboration_note" />
20+
<field name="product_uom_qty" />
21+
<field name="product_uom" />
22+
<field
23+
name="state"
24+
widget="badge"
25+
decoration-success="state == 'done'"
26+
decoration-info="state not in ('done', 'cancel')"
27+
/>
28+
</list>
29+
</field>
30+
</record>
31+
<record id="view_move_search" model="ir.ui.view">
32+
<field name="model">stock.move</field>
33+
<field name="inherit_id" ref="stock.view_move_search" />
34+
<field name="arch" type="xml">
35+
<field name="product_id" position="after">
36+
<separator />
37+
<field
38+
name="date"
39+
filter_domain="[('date','&gt;=', self)]"
40+
string="After Date"
41+
/>
42+
<field name="elaboration_ids" />
43+
<field name="elaboration_note" />
44+
<filter
45+
string="Is Elaboration"
46+
domain="['|', ('elaboration_ids', '!=', False), ('elaboration_note', '!=', '')]"
47+
name="is_elaboration"
48+
/>
49+
<separator />
50+
</field>
51+
<group position="inside">
52+
<filter
53+
string="Elaboration"
54+
context="{'group_by':'elaboration_ids'}"
55+
name="elaboration_grouped"
56+
/>
57+
</group>
58+
</field>
59+
</record>
60+
<record id="stock_move_elaboration_report_action" model="ir.actions.act_window">
61+
<field name="name">Elaborations Report</field>
62+
<field name="type">ir.actions.act_window</field>
63+
<field name="res_model">stock.move</field>
64+
<field name="view_mode">list</field>
65+
<field
66+
name="domain"
67+
>[('state', 'not in', ['done', 'cancel']), ('origin_returned_move_id', '=', False)]</field>
68+
<field name="context">{'search_default_is_elaboration':1}</field>
69+
<field name="search_view_id" ref="view_move_search" />
70+
<field
71+
name="view_ids"
72+
eval="[(5, 0, 0),
73+
(0, 0, {'view_mode': 'list', 'view_id': ref('sale_elaboration.report_stock_move_elaboration_view_tree')}),
74+
(0, 0, {'view_mode': 'pivot', 'view_id': ref('stock.view_move_pivot')}),
75+
]"
76+
/>
77+
</record>
78+
<menuitem
79+
id="menu_sale_stock_move_elaboration_report"
80+
action="stock_move_elaboration_report_action"
81+
parent="sale.menu_sale_report"
82+
sequence="70"
83+
/>
84+
<!-- Allow inventory users to access to elaboration report -->
85+
<menuitem
86+
id="menu_stock_sale_stock_move_elaboration_report"
87+
action="stock_move_elaboration_report_action"
88+
parent="stock.menu_warehouse_report"
89+
sequence="160"
90+
/>
91+
</odoo>

0 commit comments

Comments
 (0)