Skip to content

Commit

Permalink
[16.0][ADD] stock_lot_last_move_locations: In stock lot new field "La…
Browse files Browse the repository at this point in the history
…st Move Locations".
  • Loading branch information
alfredoavanzosc authored and anajuaristi committed Dec 5, 2024
1 parent 7e09fff commit d2b2eb9
Show file tree
Hide file tree
Showing 14 changed files with 302 additions and 0 deletions.
6 changes: 6 additions & 0 deletions setup/stock_lot_last_move_locations/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
29 changes: 29 additions & 0 deletions stock_lot_last_move_locations/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3

=============================
Stock lot last move locations
=============================

* In lots, new field "Last Move Locations", with the from and to locations of
the last "stock move line" performed for that lot.

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

Bugs are tracked on `GitHub Issues
<https://github.com/avanzosc/odoo-addons/issues>`_. In case of trouble,
please check there if your issue has already been reported. If you spotted
it first, help us smash it by providing detailed and welcomed feedback.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Contributors
------------

* Ana Juaristi <anajuaristi@avanzosc.es>
* Alfredo de la Fuente <alfredodelafuente@avanzosc.es>
18 changes: 18 additions & 0 deletions stock_lot_last_move_locations/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from . import models
from odoo import api, SUPERUSER_ID


def _post_install_put_last_move_locations_in_lots(cr, registry):
"""
This method will set the production cost on already done manufacturing orders.
"""
env = api.Environment(cr, SUPERUSER_ID, {})
lots = env["stock.lot"].search([])
for lot in lots:
cond = [("qty_done", ">", 0), ("state", "=", "done"), ("lot_id", "=", lot.id)]
lines = env["stock.move.line"].search(cond)
if lines:
latest_line = lines.sorted(key=lambda line: line.write_date, reverse=True)[
0
]
latest_line._put_last_move_locations_in_lots()
16 changes: 16 additions & 0 deletions stock_lot_last_move_locations/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2024 Alfredo de la Fuente - AvanzOSC
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
{
"name": "Stock Lot Last Move Locations",
"version": "16.0.1.0.0",
"license": "AGPL-3",
"author": "Avanzosc",
"category": "Inventory/Inventory",
"website": "https://github.com/avanzosc/odoo-addons",
"depends": ["product", "stock"],
"data": [
"views/stock_lot_views.xml",
],
"installable": True,
"post_init_hook": "_post_install_put_last_move_locations_in_lots",
}
32 changes: 32 additions & 0 deletions stock_lot_last_move_locations/i18n/ca_ES.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * stock_lot_last_move_locations
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-12-02 10:47+0000\n"
"PO-Revision-Date: 2024-12-02 10:47+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: stock_lot_last_move_locations
#: model:ir.model.fields,field_description:stock_lot_last_move_locations.field_stock_lot__last_move_locations
#: model_terms:ir.ui.view,arch_db:stock_lot_last_move_locations.search_product_lot_filter
msgid "Last Move Locations"
msgstr ""

#. module: stock_lot_last_move_locations
#: model:ir.model,name:stock_lot_last_move_locations.model_stock_lot
msgid "Lot/Serial"
msgstr "Lot/núm. de sèrie"

#. module: stock_lot_last_move_locations
#: model:ir.model,name:stock_lot_last_move_locations.model_stock_move_line
msgid "Product Moves (Stock Move Line)"
msgstr "Moviment del producte (línia de moviment d'estoc)"
32 changes: 32 additions & 0 deletions stock_lot_last_move_locations/i18n/en_GB.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * stock_lot_last_move_locations
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-12-02 10:47+0000\n"
"PO-Revision-Date: 2024-12-02 10:47+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: stock_lot_last_move_locations
#: model:ir.model.fields,field_description:stock_lot_last_move_locations.field_stock_lot__last_move_locations
#: model_terms:ir.ui.view,arch_db:stock_lot_last_move_locations.search_product_lot_filter
msgid "Last Move Locations"
msgstr ""

#. module: stock_lot_last_move_locations
#: model:ir.model,name:stock_lot_last_move_locations.model_stock_lot
msgid "Lot/Serial"
msgstr ""

#. module: stock_lot_last_move_locations
#: model:ir.model,name:stock_lot_last_move_locations.model_stock_move_line
msgid "Product Moves (Stock Move Line)"
msgstr ""
32 changes: 32 additions & 0 deletions stock_lot_last_move_locations/i18n/es.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * stock_lot_last_move_locations
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-12-02 10:48+0000\n"
"PO-Revision-Date: 2024-12-02 10:48+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: stock_lot_last_move_locations
#: model:ir.model.fields,field_description:stock_lot_last_move_locations.field_stock_lot__last_move_locations
#: model_terms:ir.ui.view,arch_db:stock_lot_last_move_locations.search_product_lot_filter
msgid "Last Move Locations"
msgstr "Ubic. Último Mvto."

#. module: stock_lot_last_move_locations
#: model:ir.model,name:stock_lot_last_move_locations.model_stock_lot
msgid "Lot/Serial"
msgstr "Lote/Número de serie"

#. module: stock_lot_last_move_locations
#: model:ir.model,name:stock_lot_last_move_locations.model_stock_move_line
msgid "Product Moves (Stock Move Line)"
msgstr "Movimientos de Producto (Stock Move Line)"
32 changes: 32 additions & 0 deletions stock_lot_last_move_locations/i18n/fr.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * stock_lot_last_move_locations
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-12-02 10:48+0000\n"
"PO-Revision-Date: 2024-12-02 10:48+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: stock_lot_last_move_locations
#: model:ir.model.fields,field_description:stock_lot_last_move_locations.field_stock_lot__last_move_locations
#: model_terms:ir.ui.view,arch_db:stock_lot_last_move_locations.search_product_lot_filter
msgid "Last Move Locations"
msgstr ""

#. module: stock_lot_last_move_locations
#: model:ir.model,name:stock_lot_last_move_locations.model_stock_lot
msgid "Lot/Serial"
msgstr "Lot/série"

#. module: stock_lot_last_move_locations
#: model:ir.model,name:stock_lot_last_move_locations.model_stock_move_line
msgid "Product Moves (Stock Move Line)"
msgstr "Mouvements de stock"
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * stock_lot_last_move_locations
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-12-02 10:47+0000\n"
"PO-Revision-Date: 2024-12-02 10:47+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: stock_lot_last_move_locations
#: model:ir.model.fields,field_description:stock_lot_last_move_locations.field_stock_lot__last_move_locations
#: model_terms:ir.ui.view,arch_db:stock_lot_last_move_locations.search_product_lot_filter
msgid "Last Move Locations"
msgstr ""

#. module: stock_lot_last_move_locations
#: model:ir.model,name:stock_lot_last_move_locations.model_stock_lot
msgid "Lot/Serial"
msgstr ""

#. module: stock_lot_last_move_locations
#: model:ir.model,name:stock_lot_last_move_locations.model_stock_move_line
msgid "Product Moves (Stock Move Line)"
msgstr ""
2 changes: 2 additions & 0 deletions stock_lot_last_move_locations/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import stock_lot
from . import stock_move_line
9 changes: 9 additions & 0 deletions stock_lot_last_move_locations/models/stock_lot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright 2024 Alfredo de la Fuente - AvanzOSC
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import fields, models


class StockLot(models.Model):
_inherit = "stock.lot"

last_move_locations = fields.Char(copy=False)
21 changes: 21 additions & 0 deletions stock_lot_last_move_locations/models/stock_move_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright 2024 Alfredo de la Fuente - AvanzOSC
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import models


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

def write(self, vals):
result = super().write(vals)
if "qty_done" in vals:
self._put_last_move_locations_in_lots()
return result

def _put_last_move_locations_in_lots(self):
for line in self.filtered(lambda x: x.move_id.state == "done" and x.lot_id):
last_move_locations = ("%s - %s") % (
line.location_id.name,
line.location_dest_id.name,
)
line.lot_id.last_move_locations = last_move_locations
40 changes: 40 additions & 0 deletions stock_lot_last_move_locations/views/stock_lot_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="view_production_lot_form" model="ir.ui.view">
<field name="model">stock.lot</field>
<field name="inherit_id" ref="stock.view_production_lot_form" />
<field name="arch" type="xml">
<field name="company_id" position="after">
<field name="last_move_locations" readonly="1" />
</field>
</field>
</record>

<record id="view_production_lot_tree" model="ir.ui.view">
<field name="model">stock.lot</field>
<field name="inherit_id" ref="stock.view_production_lot_tree" />
<field name="arch" type="xml">
<field name="company_id" position="before">
<field name="last_move_locations" readonly="1" optional="show" />
</field>
</field>
</record>

<record id="search_product_lot_filter" model="ir.ui.view">
<field name="model">stock.lot</field>
<field name="inherit_id" ref="stock.search_product_lot_filter" />
<field name="arch" type="xml">
<field name="product_id" position="after">
<field name="last_move_locations" />
</field>
<filter name="group_by_product" position="after">
<filter
name="group_last_move_locations"
string="Last Move Locations"
domain="[]"
context="{'group_by': 'last_move_locations'}"
/>
</filter>
</field>
</record>
</odoo>

0 comments on commit d2b2eb9

Please sign in to comment.