Skip to content

Commit

Permalink
[MIG] stock_picking_line_sequence: Migration to 14.0
Browse files Browse the repository at this point in the history
  • Loading branch information
cjallais committed Feb 4, 2021
1 parent 65e2c2f commit 63af37b
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 14 deletions.
5 changes: 3 additions & 2 deletions stock_picking_line_sequence/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Stock picking lines with sequence number
:target: https://runbot.odoo-community.org/runbot/154/12.0
:alt: Try me on Runbot

|badge1| |badge2| |badge3| |badge4| |badge5|
|badge1| |badge2| |badge3| |badge4| |badge5|


Provide a new field sequence on stock moves, which allows to manage the order of moves in a picking.
Expand Down Expand Up @@ -53,14 +53,15 @@ Credits
Authors
~~~~~~~

* ArcheTI
* Camptocamp
* Eficent
* Serpent CS

Contributors
~~~~~~~~~~~~


* Cécile Jallais <cjallais@archeti.com>
* Alexandre Fayolle <alexandre.fayolle@camptocamp.com>
* Damien Crier <damien.crier@camptocamp.com>
* Eficent Business and IT Consulting Services S.L. <contact@eficent.com>
Expand Down
3 changes: 2 additions & 1 deletion stock_picking_line_sequence/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"author": "Camptocamp, "
"Eficent, "
"Serpent CS, "
"Odoo Community Association (OCA)",
"Odoo Community Association (OCA), "
"ArcheTI",
"website": "https://github.com/OCA/stock-logistics-workflow",
"depends": ["stock", "sale", "sale_stock"],
"data": [
Expand Down
32 changes: 28 additions & 4 deletions stock_picking_line_sequence/models/stock.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,37 @@ def create(self, values):
return move


class StockMoveLine(models.Model):
_inherit = "stock.move.line"

def _get_aggregated_product_quantities(self, **kwargs):
aggregated_move_lines = super(
StockMoveLine, self
)._get_aggregated_product_quantities(**kwargs)
for move_line in self:
name = move_line.product_id.display_name
description = move_line.move_id.description_picking
if description == name or description == move_line.product_id.name:
description = False
uom = move_line.product_uom_id
line_key = (
str(move_line.product_id.id)
+ "_"
+ name
+ (description or "")
+ "uom "
+ str(uom.id)
)
sequence2 = move_line.move_id.sequence2
if line_key in aggregated_move_lines:
aggregated_move_lines[line_key]["sequence2"] = sequence2

return aggregated_move_lines


class StockPicking(models.Model):
_inherit = "stock.picking"

@api.multi
@api.depends("move_ids_without_package")
def _compute_max_line_sequence(self):
"""Allow to know the highest sequence entered in move lines.
Expand All @@ -52,21 +79,18 @@ def _compute_max_line_sequence(self):
string="Max sequence in lines", compute="_compute_max_line_sequence"
)

@api.multi
def _reset_sequence(self):
for rec in self:
current_sequence = 1
for line in rec.move_ids_without_package:
line.sequence = current_sequence
current_sequence += 1

@api.multi
def copy(self, default=None):
return super(StockPicking, self.with_context(keep_line_sequence=True)).copy(
default
)

@api.multi
def button_validate(self):
return super(
StockPicking, self.with_context(keep_line_sequence=True)
Expand Down
1 change: 1 addition & 0 deletions stock_picking_line_sequence/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

* Cécile Jallais <cjallais@archeti.com>
* Alexandre Fayolle <alexandre.fayolle@camptocamp.com>
* Damien Crier <damien.crier@camptocamp.com>
* Eficent Business and IT Consulting Services S.L. <contact@eficent.com>
Expand Down
23 changes: 19 additions & 4 deletions stock_picking_line_sequence/report/report_deliveryslip.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,33 @@
<odoo>

<template id="report_delivery_document" inherit_id="stock.report_delivery_document">
<xpath expr="//table[2]/thead/tr/th[1]" position="before">
<xpath expr="//table[1]/thead/tr/th[1]" position="before">
<th><strong>Seq.</strong></th>
</xpath>
<xpath expr="//table[2]/tbody/tr/td[1]" position="before">
<xpath expr="//table[1]/tbody/tr/td[1]" position="before">
<td><span t-field="move.sequence2" /></td>
</xpath>
<xpath expr="//table[3]/thead/tr/th[1]" position="before">
<xpath expr="//table[2]/thead/tr/th[1]" position="before">
<th><strong>Seq.</strong></th>
</xpath>
<xpath expr="//table[3]/tbody/tr/td[1]" position="before">
</template>

<template
id="report_delivery_has_serial_moveline"
inherit_id="stock.stock_report_delivery_has_serial_move_line"
>
<xpath expr="//td[1]" position="before">
<td><span t-field="move_line.move_id.sequence2" /></td>
</xpath>
</template>

<template
id="report_delivery_aggregated_moveline"
inherit_id="stock.stock_report_delivery_aggregated_move_lines"
>
<xpath expr="//td[1]" position="before">
<td><span t-esc="aggregated_lines[line]['sequence2']" /></td>
</xpath>
</template>

</odoo>
27 changes: 24 additions & 3 deletions stock_picking_line_sequence/tests/test_move_lines_sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,12 @@ def test_backorder(self):
picking.action_confirm()
picking.action_assign()
picking.move_line_ids[1].write({"qty_done": 5})
backorder_wiz_id = picking.button_validate()["res_id"]
backorder_wiz = self.env["stock.backorder.confirmation"].browse(
[backorder_wiz_id]
res_dict = picking.button_validate()
self.assertEqual(res_dict["res_model"], "stock.backorder.confirmation")
backorder_wiz = (
self.env["stock.backorder.confirmation"]
.browse(res_dict.get("res_id"))
.with_context(res_dict["context"])
)
backorder_wiz.process()
picking_backorder = self.Picking.search([("backorder_id", "=", picking.id)])
Expand All @@ -107,3 +110,21 @@ def test_backorder(self):
self.assertEqual(
picking_backorder[0].move_lines[0].sequence, 1, "Backorder wrong sequence"
)

def test_move_lines_aggregated(self):
picking = self._create_picking()
picking._compute_max_line_sequence()
picking.action_confirm()
agg_mls = picking.move_line_ids[0]._get_aggregated_product_quantities()
for key in agg_mls:
self.assertNotEqual(
agg_mls[key].get("sequence2", "NA"),
"NA",
"The field sequence2 is not added in dictionary",
)
self.assertEqual(
picking.move_line_ids[0].move_id.sequence2,
agg_mls[key]["sequence2"],
"The Sequence is not copied properly in the aggregated move lines",
)
break

0 comments on commit 63af37b

Please sign in to comment.