Add module stock_move_line_auto_fill_all

Same as the OCA module stock_move_line_auto_fill but applies on all
moves lines (including lines with lot)
This commit is contained in:
Alexis de Lattre
2023-04-28 12:49:37 +02:00
parent 16ed41187f
commit 2863de99f4
5 changed files with 85 additions and 0 deletions

View File

@@ -0,0 +1 @@
from . import models

View File

@@ -0,0 +1,27 @@
# Copyright 2023 Akretion France (http://www.akretion.com/)
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
'name': 'Stock Move Line Auto-fill All',
'version': '14.0.1.0.0',
'category': 'Warehouse',
'license': 'AGPL-3',
'summary': 'Add button on picking to auto-fill done qty',
'description': """
This module is an alternative to the OCA module **stock_move_line_auto_fill** from https://github.com/OCA/stock-logistics-workflow/
The OCA module doesn't auto-fill the stock move lines with lots. This module does.
This module has been written by Alexis de Lattre from Akretion
<alexis.delattre@akretion.com>.
""",
'author': 'Akretion',
'maintainers': ['alexis-via'],
"development_status": "Mature",
'website': 'https://github.com/akretion/odoo-usability',
'depends': ['stock'],
'data': [
'views/stock_picking.xml',
],
'installable': True,
}

View File

@@ -0,0 +1 @@
from . import stock_picking

View File

@@ -0,0 +1,34 @@
# Copyright 2023 Akretion France (http://www.akretion.com/)
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import fields, models, _
from odoo.tools import float_compare, float_is_zero
from odoo.exceptions import UserError
class StockPicking(models.Model):
_inherit = 'stock.picking'
autofill_done = fields.Boolean(readonly=True)
def button_stock_move_line_autofill(self):
self.ensure_one()
prec = self.env['decimal.precision'].precision_get(
'Product Unit of Measure')
for ml in self.move_line_ids_without_package:
if ml.product_id and float_compare(ml.product_uom_qty, 0, precision_digits=prec) > 0 and float_is_zero(ml.qty_done, precision_digits=prec):
if (
ml.product_id.tracking in ('lot', 'serial') and
not ml.lot_id and
not ml.lot_name):
raise UserError(_(
"Autofill is not possible: the lot is not set "
"on move line with product '%s' quantity %s %s.")
% (
ml.product_id.display_name,
ml.product_uom_qty,
ml.product_uom_id.display_name
))
ml.write({'qty_done': ml.product_uom_qty})
self.write({'autofill_done': True})

View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2023 Akretion France (http://www.akretion.com/)
@author: Alexis de Lattre <alexis.delattre@akretion.com>
-->
<odoo>
<record id="view_picking_form" model="ir.ui.view">
<field name="model">stock.picking</field>
<field name="inherit_id" ref="stock.view_picking_form"/>
<field name="arch" type="xml">
<button name="button_validate" type="object" class="oe_highlight" position="before">
<button name="button_stock_move_line_autofill" type="object" string="Auto-Fill" attrs="{'invisible': ['|', ('state', '!=', 'assigned'), ('autofill_done', '=', True)]}" groups="stock.group_stock_user" help="This button will copy the 'Reserved' qty on the 'Done' qty for all the operations of this picking with a null 'Done' qty."/>
</button>
<field name="origin" position="after">
<field name="autofill_done" invisible="1"/>
</field>
</field>
</record>
</odoo>