Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[15.0][ADD] mrp_weighing: Add module #12

Merged
merged 1 commit into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions mrp_weighing/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
====================================
Weighing assistant in batch pickings
====================================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:4c66742998294dc1a2cda1baab1b6a2921b00c423fe8325408af433c2543a566
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |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/mrp_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-mrp_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|

Weighing production finished moves

**Table of contents**

.. contents::
:local:

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:%20mrp_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>`__

- Sergio Teruel
- Carlos Dauden

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/mrp_weighing>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
3 changes: 3 additions & 0 deletions mrp_weighing/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
from . import models
from . import wizards
16 changes: 16 additions & 0 deletions mrp_weighing/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2024 Tecnativa - Sergio Teruel
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
{
"name": "Weighing assistant in batch pickings",
"summary": "Launch the weighing assistant from batch pickings",
"version": "15.0.1.0.0",
"author": "Tecnativa, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/stock-weighing",
"license": "AGPL-3",
"category": "MRP",
"depends": [
"stock_weighing",
"mrp",
],
"data": ["views/mrp_production_view.xml"],
}
3 changes: 3 additions & 0 deletions mrp_weighing/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
from . import mrp_production
from . import stock_move
36 changes: 36 additions & 0 deletions mrp_weighing/models/mrp_production.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Copyright 2024 Tecnativa - Sergio Teruel
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
import ast

from odoo import _, api, fields, models


class MrpProduction(models.Model):
_inherit = "mrp.production"

weighing_operations = fields.Boolean(related="picking_type_id.weighing_operations")
has_weighing_operations = fields.Boolean(compute="_compute_has_weighing_operations")

@api.depends("move_finished_ids")
def _compute_has_weighing_operations(self):
for mrp_production in self:
mrp_production.has_weighing_operations = mrp_production.move_finished_ids

Check warning on line 17 in mrp_weighing/models/mrp_production.py

View check run for this annotation

Codecov / codecov/patch

mrp_weighing/models/mrp_production.py#L17

Added line #L17 was not covered by tests

def action_weighing_operations(self):
"""Weighing operations for this production order"""
action = self.env["ir.actions.actions"]._for_xml_id(

Check warning on line 21 in mrp_weighing/models/mrp_production.py

View check run for this annotation

Codecov / codecov/patch

mrp_weighing/models/mrp_production.py#L21

Added line #L21 was not covered by tests
"stock_weighing.weighing_operation_action"
)
weight_moves = self.move_finished_ids
action["name"] = _("Weighing operations for %(name)s", name=self.name)
action["domain"] = [("id", "in", weight_moves.ids)]
ctx = dict(

Check warning on line 27 in mrp_weighing/models/mrp_production.py

View check run for this annotation

Codecov / codecov/patch

mrp_weighing/models/mrp_production.py#L24-L27

Added lines #L24 - L27 were not covered by tests
self.env.context,
**ast.literal_eval(action["context"]),
group_by=["production_id"],
show_weight_detail_buttons=True
)
# We weigh mrp operations that are not in ready state
ctx.pop("search_default_ready")
action["context"] = ctx
return action

Check warning on line 36 in mrp_weighing/models/mrp_production.py

View check run for this annotation

Codecov / codecov/patch

mrp_weighing/models/mrp_production.py#L34-L36

Added lines #L34 - L36 were not covered by tests
53 changes: 53 additions & 0 deletions mrp_weighing/models/stock_move.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Copyright 2024 Tecnativa - Sergio Teruel
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
from odoo import api, models


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

@api.model
def action_mrp_production_weighing(self):
"""Used in the start screen"""
action = self.env["ir.actions.actions"]._for_xml_id("mrp.mrp_production_action")
ctx = {"search_default_todo": True}
action["context"] = ctx
return action

Check warning on line 15 in mrp_weighing/models/stock_move.py

View check run for this annotation

Codecov / codecov/patch

mrp_weighing/models/stock_move.py#L12-L15

Added lines #L12 - L15 were not covered by tests

def action_add_move_line(self):
action = super().action_add_move_line()

Check warning on line 18 in mrp_weighing/models/stock_move.py

View check run for this annotation

Codecov / codecov/patch

mrp_weighing/models/stock_move.py#L18

Added line #L18 was not covered by tests
if not self.production_id.lot_producing_id:
return action
default_lot_id = False

Check warning on line 21 in mrp_weighing/models/stock_move.py

View check run for this annotation

Codecov / codecov/patch

mrp_weighing/models/stock_move.py#L20-L21

Added lines #L20 - L21 were not covered by tests
if self.product_id == self.production_id.product_id:
default_lot_id = self.production_id.lot_producing_id.id

Check warning on line 23 in mrp_weighing/models/stock_move.py

View check run for this annotation

Codecov / codecov/patch

mrp_weighing/models/stock_move.py#L23

Added line #L23 was not covered by tests
else:
last_lot = self.move_line_ids.lot_id[-1:]

Check warning on line 25 in mrp_weighing/models/stock_move.py

View check run for this annotation

Codecov / codecov/patch

mrp_weighing/models/stock_move.py#L25

Added line #L25 was not covered by tests
if last_lot:
default_lot_id = last_lot.id

Check warning on line 27 in mrp_weighing/models/stock_move.py

View check run for this annotation

Codecov / codecov/patch

mrp_weighing/models/stock_move.py#L27

Added line #L27 was not covered by tests
elif self.has_tracking:
lot = self.env["stock.production.lot"].search(

Check warning on line 29 in mrp_weighing/models/stock_move.py

View check run for this annotation

Codecov / codecov/patch

mrp_weighing/models/stock_move.py#L29

Added line #L29 was not covered by tests
[
("company_id", "=", self.company_id.id),
("product_id", "=", self.product_id.id),
("name", "=", self.production_id.lot_producing_id.name),
],
limit=1,
)
if lot:
default_lot_id = lot.id

Check warning on line 38 in mrp_weighing/models/stock_move.py

View check run for this annotation

Codecov / codecov/patch

mrp_weighing/models/stock_move.py#L38

Added line #L38 was not covered by tests
else:
sml = self.move_line_ids[:1]

Check warning on line 40 in mrp_weighing/models/stock_move.py

View check run for this annotation

Codecov / codecov/patch

mrp_weighing/models/stock_move.py#L40

Added line #L40 was not covered by tests
if not sml:
sml = self.env["stock.move.line"].new(

Check warning on line 42 in mrp_weighing/models/stock_move.py

View check run for this annotation

Codecov / codecov/patch

mrp_weighing/models/stock_move.py#L42

Added line #L42 was not covered by tests
{
"lot_name": self.production_id.lot_producing_id.name,
"product_id": self.product_id.id,
"company_id": self.company_id.id,
}
)
sml._create_and_assign_production_lot()
default_lot_id = sml.lot_id.id

Check warning on line 50 in mrp_weighing/models/stock_move.py

View check run for this annotation

Codecov / codecov/patch

mrp_weighing/models/stock_move.py#L49-L50

Added lines #L49 - L50 were not covered by tests
if default_lot_id:
action["context"].update({"default_lot_id": default_lot_id})
return action

Check warning on line 53 in mrp_weighing/models/stock_move.py

View check run for this annotation

Codecov / codecov/patch

mrp_weighing/models/stock_move.py#L52-L53

Added lines #L52 - L53 were not covered by tests
3 changes: 3 additions & 0 deletions mrp_weighing/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- [Tecnativa](https://www.tecnativa.com)
- Sergio Teruel
- Carlos Dauden
1 change: 1 addition & 0 deletions mrp_weighing/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Weighing production finished moves
Loading
Loading