Skip to content

Commit

Permalink
[ADD] stock_weighing: New module
Browse files Browse the repository at this point in the history
TT47127
  • Loading branch information
chienandalu committed May 31, 2024
1 parent 8d07d0f commit 2b8f0b2
Show file tree
Hide file tree
Showing 44 changed files with 2,423 additions and 1 deletion.
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

exclude: |
(?x)
# NOT INSTALLABLE ADDONS
Expand Down
2 changes: 2 additions & 0 deletions setup/.setuptools-odoo-make-default-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# addons listed in this file are ignored by
# setuptools-odoo-make-default (one addon per line)
2 changes: 2 additions & 0 deletions setup/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
To learn more about this directory, please visit
https://pypi.python.org/pypi/setuptools-odoo
1 change: 1 addition & 0 deletions setup/stock_weighing/odoo/addons/stock_weighing
6 changes: 6 additions & 0 deletions setup/stock_weighing/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,
)
159 changes: 159 additions & 0 deletions stock_weighing/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
==================
Weighing assistant
==================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:9f20f82a50a6f75d07c87cec07e8dda0c359770fae19121cb231a7bc35a17cfe
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fstock--weighing-lightgray.png?logo=github
:target: https://github.com/OCA/stock-weighing/tree/15.0/stock_weighing
:alt: OCA/stock-weighing
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/stock-weighing-15-0/stock-weighing-15-0-stock_weighing
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/stock-weighing&target_branch=15.0
:alt: Try me on Runboat

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

A shopfloor assistant for weighing on stock operations.

**Table of contents**

.. contents::
:local:

Use Cases / Context
===================

Some bussiness must weigh their operations in order to process them. For
example in fresh product factories where the demand could not fit the
exact a amount of delivered product and that depends on the final
operation weight.

Configuration
=============

You need to configure an operation type so its operations show up in the
weighing assistant.

To do so:

1. Go to *Configuration > Operations Types* and choose the one you want
to configure.
2. Set *Weighing operations* on.
3. You can choose your desired *Weighing lable report*.
4. If you want to print your labels automatically, set *Print weighing
label* on.

If you don't have any product with units of measure of the weight
category, you'll have to add some.

- Allow to show the units of measure in your config settings if isn't
ready yet.
- Add some products with a unit of measure of the weight category
(kilograms, grams, etc.).
- Place some pending operations for those products.

Usage
=====

You've got several ways to start weighing pending operations:

**From the app menu**

1. Go to the app menu an click on *Weighing*
2. You'll be presented with your weighing options (Incoming, Outgoing or
more if a third module extends it)
3. You can start weighing.

**From a weighing operation type**

1. Go to *Inventory > Overview*.
2. Those operation types with *weighing operation* active will show a
button with the pending ones.
3. Click on it and you can start weighing.

**From a picking**

1. In any picking with weighing operations, you can click on the smart
button and start processing them.

Using the assitant
------------------

You'll be presented with a list of operations to weigh. To weigh them,
just press the red circle button to record a new weight:

- If there's only one detailed operation reserved, a popup will show up
to record the operation weight.
- If there are several, you'll enter the detailed view and you'll be
able to weigh every detailed operation.
- If you just want to weigh one, you can force the operation as done
using the checkmark button.

You can reset your weighing using the cross button. You can print the
label on demand using the printer button. You can add a new detailed
operation using the plus button.

Known issues / Roadmap
======================

- This PR should be https://github.com/odoo/odoo/pull/161042 merged in
order to reload the kanban view properly after each action. Otherwise
we should reimplement the whole core method in our override.

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

Bugs are tracked on `GitHub Issues <https://github.com/OCA/stock-weighing/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/stock-weighing/issues/new?body=module:%20stock_weighing%0Aversion:%2015.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.

Credits
=======

Authors
-------

* Tecnativa

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

- `Tecnativa <https://www.tecnativa.com>`__

- David Vidal
- Sergio Teruel

Maintainers
-----------

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

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/stock-weighing <https://github.com/OCA/stock-weighing/tree/15.0/stock_weighing>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
4 changes: 4 additions & 0 deletions stock_weighing/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from . import controllers
from . import models
from . import wizards
from .init_hook import pre_init_hook, post_init_hook
40 changes: 40 additions & 0 deletions stock_weighing/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright 2024 Tecnativa - David Vidal
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
{
"name": "Weighing assistant",
"summary": "Weighing assistant for stock operations",
"version": "15.0.1.0.0",
"author": "Tecnativa, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/stock-weighing",
"license": "AGPL-3",
"category": "Inventory",
"depends": [
"stock",
"web_filter_header_button",
],
"data": [
"security/ir.model.access.csv",
"views/start_screen_banner.xml",
"wizards/weigh_operation_selection_views.xml",
"views/stock_move_line_views.xml",
"views/stock_move_views.xml",
"views/stock_picking_views.xml",
"views/stock_picking_type_views.xml",
"wizards/weighing_wizard_views.xml",
],
"demo": [
"demo/weight_label_demo.xml",
"demo/picking_type_demo.xml",
],
"assets": {
"web.assets_backend": [
"stock_weighing/static/src/**/*.scss",
"stock_weighing/static/src/**/*.js",
],
"web.assets_qweb": [
"stock_weighing/static/src/**/*.xml",
],
},
"post_init_hook": "post_init_hook",
"pre_init_hook": "pre_init_hook",
}
1 change: 1 addition & 0 deletions stock_weighing/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import start_screen
21 changes: 21 additions & 0 deletions stock_weighing/controllers/start_screen.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright 2024 Tecnativa - David Vidal
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import http
from odoo.http import request


class StockWeighing(http.Controller):
@http.route("/stock_weighing/start_screen", auth="user", type="json")
def stock_weighing_start_screen(self):
"""Returns the banner for the weighing options"""
return {

Check warning on line 11 in stock_weighing/controllers/start_screen.py

View check run for this annotation

Codecov / codecov/patch

stock_weighing/controllers/start_screen.py#L11

Added line #L11 was not covered by tests
"html": request.env.ref(
"stock_weighing.stock_weighing_start_screen"
)._render(
{
"actions": request.env[
"weigh.operation.selection"
]._get_weighing_start_screen_actions()
}
)
}
11 changes: 11 additions & 0 deletions stock_weighing/demo/picking_type_demo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="stock.picking_type_out" model="stock.picking.type">
<field name="weighing_operations" eval="True" />
<field name="print_weighing_label" eval="True" />
<field
name="weighing_label_report_id"
ref="stock_weighing.label_weight_record"
/>
</record>
</odoo>
37 changes: 37 additions & 0 deletions stock_weighing/demo/weight_label_demo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<template id="report_weight_record_label">
<t t-call="web.basic_layout">
<div class="page">
<!-- Don't print empty labels -->
<t t-foreach="docs.filtered('qty_done')" t-as="sml">
<t t-set="lot_name" t-value="sml.lot_id.name or sml.lot_name" />
<div class="o_label_page o_label_dymo">
<div>
<span t-out="sml.product_id.display_name" />
</div>
<div class="h5 pt-2">
<span
t-out="sml.qty_done"
t-options="{'widget': 'float', 'decimal_precision': 'Product Unit of Measure'}"
/> <span t-out="sml.product_uom_id.name" />
</div>
<div t-if="lot_name">
<span>LOT: <t t-out="lot_name" /></span>
</div>
<div t-out="sml.move_id.reference" />
</div>
</t>
</div>
</t>
</template>
<record id="label_weight_record" model="ir.actions.report">
<field name="name">Weight Record Label</field>
<field name="model">stock.move.line</field>
<field name="report_type">qweb-pdf</field>
<field name="report_name">stock_weighing.report_weight_record_label</field>
<field name="report_file">stock_weighing.report_weight_record_label</field>
<field name="paperformat_id" ref="product.paperformat_label_sheet_dymo" />
<field name="binding_type">report</field>
</record>
</odoo>
24 changes: 24 additions & 0 deletions stock_weighing/init_hook.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright 2024 Tecnativa - David Vidal
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
import logging

from odoo import SUPERUSER_ID, api

_logger = logging.getLogger(__name__)


def pre_init_hook(cr):
_logger.info("Pre-creating weighing state column to avoid computing everyone...")
cr.execute("ALTER TABLE stock_move ADD COLUMN IF NOT EXISTS weighing_state VARCHAR")


def post_init_hook(cr, registry):
"""Recompute weighing_state only in pending moves"""
env = api.Environment(cr, SUPERUSER_ID, {})
_logger.info("Computing weighing state on pending moves...")
env["stock.move"].search(
[
("has_weight", "=", True),
("state", "in", ("assigned", "confirmed", "waiting")),
]
)._compute_weighing_state()
5 changes: 5 additions & 0 deletions stock_weighing/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from . import weighing_mixin
from . import stock_move_line
from . import stock_move
from . import stock_picking_type
from . import stock_picking
Loading

0 comments on commit 2b8f0b2

Please sign in to comment.