Skip to content

Commit

Permalink
[IMP] stock_weighing: allow to use the weigh actions with regular ope…
Browse files Browse the repository at this point in the history
…rations
  • Loading branch information
chienandalu committed Jul 17, 2024
1 parent 2381fd3 commit f8edb43
Show file tree
Hide file tree
Showing 12 changed files with 152 additions and 76 deletions.
4 changes: 4 additions & 0 deletions stock_weighing/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ category, you'll have to add some.
(kilograms, grams, etc.).
- Place some pending operations for those products.

If you want to use the weighing system for other operations you can set
the configuration parameter ``stock_weighing.any_operation_actions`` to
a true value. You'll be a able to record other values.

Usage
=====

Expand Down
5 changes: 1 addition & 4 deletions stock_weighing/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@
"website": "https://github.com/OCA/stock-weighing",
"license": "AGPL-3",
"category": "Inventory",
"depends": [
"stock",
"web_filter_header_button",
],
"depends": ["stock", "web_filter_header_button", "web_widget_numeric_step"],
"data": [
"security/ir.model.access.csv",
"views/start_screen_banner.xml",
Expand Down
2 changes: 1 addition & 1 deletion stock_weighing/i18n/es.po
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ msgstr "Los productos pesado están realizados desde operaciones de pesaje"
#: model:ir.ui.menu,name:stock_weighing.menu_weighing
#: model_terms:ir.ui.view,arch_db:stock_weighing.view_move_weight_kanban_view
msgid "Weighing"
msgstr "Peso"
msgstr "Pesaje"

#. module: stock_weighing
#: model:ir.model.fields,field_description:stock_weighing.field_stock_move_line__weighing_date
Expand Down
40 changes: 34 additions & 6 deletions stock_weighing/models/stock_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,33 +237,61 @@ def action_force_weighed(self):
self.weighing_state = "weighed"

Check warning on line 237 in stock_weighing/models/stock_move.py

View check run for this annotation

Codecov / codecov/patch

stock_weighing/models/stock_move.py#L237

Added line #L237 was not covered by tests

@api.model
def action_outgoing_weighing_operations(self):
def action_outgoing_any_operations(self):
"""Used in the start screen"""
action = self.env["ir.actions.actions"]._for_xml_id(

Check warning on line 242 in stock_weighing/models/stock_move.py

View check run for this annotation

Codecov / codecov/patch

stock_weighing/models/stock_move.py#L242

Added line #L242 was not covered by tests
"stock_weighing.weighing_operation_action"
)
action["domain"] = [

Check warning on line 245 in stock_weighing/models/stock_move.py

View check run for this annotation

Codecov / codecov/patch

stock_weighing/models/stock_move.py#L245

Added line #L245 was not covered by tests
("has_weight", "=", True),
("location_id.usage", "in", ["internal", "transit"]),
("location_dest_id.usage", "not in", ["internal", "transit"]),
("picking_type_id.weighing_operations", "=", True),
]
action["target"] = "main"
action["name"] = _("Weight outgoing")
action["context"] = dict(

Check warning on line 251 in stock_weighing/models/stock_move.py

View check run for this annotation

Codecov / codecov/patch

stock_weighing/models/stock_move.py#L250-L251

Added lines #L250 - L251 were not covered by tests
show_weight_detail_buttons=1, **ast.literal_eval(action["context"])
)
action["name"] = _("Outgoing operations")
return action

Check warning on line 255 in stock_weighing/models/stock_move.py

View check run for this annotation

Codecov / codecov/patch

stock_weighing/models/stock_move.py#L254-L255

Added lines #L254 - L255 were not covered by tests

@api.model
def action_incoming_weighing_operations(self):
def action_outgoing_weighing_operations(self):
"""Used in the start screen"""
action = self.action_outgoing_any_operations()
action["domain"] = expression.AND(

Check warning on line 261 in stock_weighing/models/stock_move.py

View check run for this annotation

Codecov / codecov/patch

stock_weighing/models/stock_move.py#L260-L261

Added lines #L260 - L261 were not covered by tests
[action["domain"], [("has_weight", "=", True)]]
)
action["context"].pop("show_weight_detail_buttons", None)
action["context"] = dict(search_default_to_weigh=1, **action["context"])
action["name"] = _("Weigh outgoing")
return action

Check warning on line 267 in stock_weighing/models/stock_move.py

View check run for this annotation

Codecov / codecov/patch

stock_weighing/models/stock_move.py#L264-L267

Added lines #L264 - L267 were not covered by tests

@api.model
def action_incoming_any_operations(self):
"""Used in the start screen"""
action = self.env["ir.actions.actions"]._for_xml_id(

Check warning on line 272 in stock_weighing/models/stock_move.py

View check run for this annotation

Codecov / codecov/patch

stock_weighing/models/stock_move.py#L272

Added line #L272 was not covered by tests
"stock_weighing.weighing_operation_action"
)
action["domain"] = [

Check warning on line 275 in stock_weighing/models/stock_move.py

View check run for this annotation

Codecov / codecov/patch

stock_weighing/models/stock_move.py#L275

Added line #L275 was not covered by tests
("has_weight", "=", True),
("location_id.usage", "not in", ["internal", "transit"]),
("location_dest_id.usage", "in", ["internal", "transit"]),
("picking_type_id.weighing_operations", "=", True),
]
action["target"] = "main"
action["name"] = _("Weight incoming")
action["context"] = dict(

Check warning on line 281 in stock_weighing/models/stock_move.py

View check run for this annotation

Codecov / codecov/patch

stock_weighing/models/stock_move.py#L280-L281

Added lines #L280 - L281 were not covered by tests
show_weight_detail_buttons=1, **ast.literal_eval(action["context"])
)
action["name"] = _("Outgoing operations")
return action

Check warning on line 285 in stock_weighing/models/stock_move.py

View check run for this annotation

Codecov / codecov/patch

stock_weighing/models/stock_move.py#L284-L285

Added lines #L284 - L285 were not covered by tests

@api.model
def action_incoming_weighing_operations(self):
"""Used in the start screen"""
action = self.action_incoming_any_operations()
action["domain"] = expression.AND(

Check warning on line 291 in stock_weighing/models/stock_move.py

View check run for this annotation

Codecov / codecov/patch

stock_weighing/models/stock_move.py#L290-L291

Added lines #L290 - L291 were not covered by tests
[action["domain"], [("has_weight", "=", True)]]
)
action["context"].pop("show_weight_detail_buttons", None)
action["context"] = dict(search_default_to_weigh=1, **action["context"])
action["name"] = _("Weigh incoming")
return action

Check warning on line 297 in stock_weighing/models/stock_move.py

View check run for this annotation

Codecov / codecov/patch

stock_weighing/models/stock_move.py#L294-L297

Added lines #L294 - L297 were not covered by tests
4 changes: 4 additions & 0 deletions stock_weighing/readme/CONFIGURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ If you don't have any product with units of measure of the weight category, you'
- 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.

If you want to use the weighing system for other operations you can set the configuration parameter
`stock_weighing.any_operation_actions` to a true value. You'll be a able to record other
values.
3 changes: 3 additions & 0 deletions stock_weighing/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,9 @@ <h1><a class="toc-backref" href="#toc-entry-2">Configuration</a></h1>
(kilograms, grams, etc.).</li>
<li>Place some pending operations for those products.</li>
</ul>
<p>If you want to use the weighing system for other operations you can set
the configuration parameter <tt class="docutils literal">stock_weighing.any_operation_actions</tt> to
a true value. You’ll be a able to record other values.</p>
</div>
<div class="section" id="usage">
<h1><a class="toc-backref" href="#toc-entry-3">Usage</a></h1>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,5 @@
input.o_input_weight {
font-size: 3em;
font-weight: bold;
width: 90%;
}
36 changes: 17 additions & 19 deletions stock_weighing/views/stock_move_line_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
<!-- Recording button -->
<div class="col-2">
<div
t-if="record.has_weight.raw_value &amp;&amp; record.state.raw_value !== 'done'"
t-if="record.state.raw_value !== 'done'"
class="row"
>
<button
Expand All @@ -79,24 +79,22 @@
</div>
<!-- Weight value -->
<div class="col-3">
<t t-if="record.has_weight.raw_value">
<div>
<t t-if="record.recorded_weight.raw_value">
<span class="h1 text-success">
<field name="recorded_weight" />
</span>
<sup class="initialism">
<field name="product_uom_id" />
</sup>
</t>
<t t-else="">
<span
class="h1 text-warning"
t-out="'--.--'"
/>
</t>
</div>
</t>
<div>
<t t-if="record.recorded_weight.raw_value">
<span class="h1 text-success">
<field name="recorded_weight" />
</span>
<sup class="initialism">
<field name="product_uom_id" />
</sup>
</t>
<t t-else="">
<span
class="h1 text-warning"
t-out="'--.--'"
/>
</t>
</div>
</div>
<div class="col-3">
<div class="row">
Expand Down
68 changes: 35 additions & 33 deletions stock_weighing/views/stock_move_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
<!-- Recording button -->
<div class="col-1">
<div
t-if="record.has_weight.raw_value &amp;&amp; !['done', 'cancel', 'draft'].includes(record.state.raw_value)"
t-if="!['done', 'cancel', 'draft'].includes(record.state.raw_value)"
class="row"
>
<button
Expand Down Expand Up @@ -150,36 +150,38 @@
</div>
<!-- Weight -->
<div class="col-2">
<t t-if="record.has_weight.raw_value">
<span
t-if="record.weighing_state.raw_value == 'weighed'"
class="badge badge-success w-100"
>Weighed</span>
<span
t-elif="record.weighing_state.raw_value == 'weighing'"
class="badge badge-warning w-100"
>Weighing</span>
<span
t-elif="record.weighing_state.raw_value == 'to_weigh'"
class="badge badge-danger w-100"
>To weigh</span>
<div class="text-center">
<t t-if="record.recorded_weight.raw_value">
<span class="h1 text-success">
<field name="recorded_weight" />
</span>
<sup class="initialism">
<field name="product_uom" />
</sup>
</t>
<t t-else="">
<span
class="h1 text-warning"
t-out="'--.--'"
/>
</t>
</div>
</t>
<span
t-if="record.weighing_state.raw_value === 'weighed'"
class="badge badge-success w-100"
>Weighed</span>
<span
t-elif="record.weighing_state.raw_value === 'weighing'"
class="badge badge-warning w-100"
>Weighing</span>
<span
t-elif="record.weighing_state.raw_value === 'to_weigh'"
class="badge badge-danger w-100"
>To weigh</span>
<span
t-else=""
t-attf-class="badge badge-{{record.recorded_weight.raw_value ? 'success' : 'light'}} w-100"
>Qty. done</span>
<div class="text-center">
<t t-if="record.recorded_weight.raw_value">
<span class="h1 text-success">
<field name="recorded_weight" />
</span>
<sup class="initialism">
<field name="product_uom" />
</sup>
</t>
<t t-else="">
<span
class="h1 text-warning"
t-out="'--.--'"
/>
</t>
</div>
</div>
<!-- Extra buttons -->
<div class="col-3">
Expand Down Expand Up @@ -226,7 +228,7 @@
<!-- Details -->
<div class="col-1">
<button
t-if="record.move_lines_count.raw_value &amp;&amp; !single_move_line &amp;&amp; !context.hide_weight_detail_buttons"
t-if="(!single_move_line &amp;&amp; !context.hide_weight_detail_buttons) || context.show_weight_detail_buttons"
type="object"
name="action_weight_detailed_operations"
t-attf-class="btn btn-lg {{single_move_line ? 'btn-secondary' : 'btn-primary'}}"
Expand Down Expand Up @@ -338,7 +340,7 @@
<field name="view_mode">kanban,form</field>
<field
name="context"
>{'search_default_ready': 1, 'search_default_date_today': 1, 'search_default_to_weigh': 1, 'outgoing_weighing_order': 1}</field>
>{'search_default_ready': 1, 'search_default_date_today': 1, 'outgoing_weighing_order': 1}</field>
<field name="domain">[('has_weight', '=', True)]</field>
<field
name="view_ids"
Expand Down
43 changes: 35 additions & 8 deletions stock_weighing/wizards/weigh_operation_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,44 @@ class WeightOperationSelection(models.TransientModel):
@api.model
def _get_weighing_start_screen_actions(self):
"""Extend to add more options to the start screen"""
return [
any_operation_actions = (

Check warning on line 13 in stock_weighing/wizards/weigh_operation_selection.py

View check run for this annotation

Codecov / codecov/patch

stock_weighing/wizards/weigh_operation_selection.py#L13

Added line #L13 was not covered by tests
self.env["ir.config_parameter"]
.sudo()
.get_param("stock_weighing.any_operation_actions")
)
actions = []
actions.append(

Check warning on line 19 in stock_weighing/wizards/weigh_operation_selection.py

View check run for this annotation

Codecov / codecov/patch

stock_weighing/wizards/weigh_operation_selection.py#L18-L19

Added lines #L18 - L19 were not covered by tests
{
"title": _("Incoming"),
"title": _("Incoming (weighing)"),
"description": _("Incoming weighing operations"),
"icon": "fa-arrow-down",
"icon": "fa-arrow-down text-success",
"method": "action_incoming_weighing_operations",
},
}
)
if any_operation_actions:
actions.append(

Check warning on line 28 in stock_weighing/wizards/weigh_operation_selection.py

View check run for this annotation

Codecov / codecov/patch

stock_weighing/wizards/weigh_operation_selection.py#L28

Added line #L28 was not covered by tests
{
"title": _("Incoming (any)"),
"description": _("Any incoming operation"),
"icon": "fa-arrow-down text-info",
"method": "action_incoming_any_operations",
}
)
actions.append(

Check warning on line 36 in stock_weighing/wizards/weigh_operation_selection.py

View check run for this annotation

Codecov / codecov/patch

stock_weighing/wizards/weigh_operation_selection.py#L36

Added line #L36 was not covered by tests
{
"title": _("Outgoing"),
"title": _("Outgoing (weighing)"),
"description": _("Outgoing weighing operations"),
"icon": "fa-arrow-right",
"icon": "fa-arrow-right text-success",
"method": "action_outgoing_weighing_operations",
},
]
}
)
if any_operation_actions:
actions.append(

Check warning on line 45 in stock_weighing/wizards/weigh_operation_selection.py

View check run for this annotation

Codecov / codecov/patch

stock_weighing/wizards/weigh_operation_selection.py#L45

Added line #L45 was not covered by tests
{
"title": _("Outgoing (any)"),
"description": _("Any outgoing operation"),
"icon": "fa-arrow-right text-info",
"method": "action_outgoing_any_operations",
}
)
return actions

Check warning on line 53 in stock_weighing/wizards/weigh_operation_selection.py

View check run for this annotation

Codecov / codecov/patch

stock_weighing/wizards/weigh_operation_selection.py#L53

Added line #L53 was not covered by tests
9 changes: 9 additions & 0 deletions stock_weighing/wizards/weighing_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class StockMoveWeightWizard(models.TransientModel):
weight = fields.Float(digits="Product Unit of Measure")
print_label = fields.Boolean(help="Print label after the weight record")
label_report_id = fields.Many2one(comodel_name="ir.actions.report")
has_weight = fields.Boolean(compute="_compute_has_weight", readonly=False)

@api.depends("product_id")
def _compute_available_lot_ids(self):
Expand All @@ -68,6 +69,14 @@ def _compute_available_result_package_ids(self):
limit=10,
)

@api.depends("move_id", "selected_move_line_id")
def _compute_has_weight(self):
self.has_weight = False

Check warning on line 74 in stock_weighing/wizards/weighing_wizard.py

View check run for this annotation

Codecov / codecov/patch

stock_weighing/wizards/weighing_wizard.py#L74

Added line #L74 was not covered by tests
for wiz in self:
wiz.has_weight = (

Check warning on line 76 in stock_weighing/wizards/weighing_wizard.py

View check run for this annotation

Codecov / codecov/patch

stock_weighing/wizards/weighing_wizard.py#L76

Added line #L76 was not covered by tests
wiz.move_id.has_weight or wiz.selected_move_line_id.has_weight
)

def _lot_creation_constraints(self):
"""To be hooked by stock_picking_auto_create_lot or others"""
return [self.product_tracking != "none", not self.lot_id]

Check warning on line 82 in stock_weighing/wizards/weighing_wizard.py

View check run for this annotation

Codecov / codecov/patch

stock_weighing/wizards/weighing_wizard.py#L82

Added line #L82 was not covered by tests
Expand Down
13 changes: 8 additions & 5 deletions stock_weighing/wizards/weighing_wizard_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
<field name="product_tracking" invisible="1" />
<field name="available_lot_ids" invisible="1" />
<field name="available_result_package_ids" invisible="1" />
<field name="has_weight" invisible="1" />
<sheet>
<group groups="stock.group_production_lot">
<group groups="stock.group_production_lot" col="1">
<field
name="lot_id"
class="form-control-lg"
class="form-control-lg pl-0"
placeholder="Select lot..."
attrs="{'invisible': ['|', ('wizard_state', '=', 'weight'), ('product_tracking', '=', 'none')]}"
options="{'no_open': True, 'no_create': True}"
Expand All @@ -24,13 +25,15 @@
</group>
<field
name="weight"
class="form-control-lg text-center text-info o_input_weight"
class="input-group-lg"
nolabel="1"
widget="numeric_step"
options="{'auto_select': True, 'min': 0, 'add_class': 'form-control-lg text-center text-info o_input_weight', 'remove_class': 'form-control'}"
/>
<group groups="stock.group_tracking_lot">
<group groups="stock.group_production_lot">
<field
name="result_package_id"
class="form-control-lg"
class="form-control-lg pl-0"
placeholder="Select destination package..."
attrs="{'invisible': [('wizard_state', '=', 'weight')]}"
options="{'no_open': True, 'no_create': True}"
Expand Down

0 comments on commit f8edb43

Please sign in to comment.