Skip to Content
Menu
This question has been flagged
6 Replies
4186 Views

When we produce many lot numbers from work order tablet view, a new manufacturing order is created for every lot number when you press 'Mark As Done' in the tablet view.

The order with the lot number that is complete stays in status "To close", and you have to manually close the manufacturing order that also post product movements.

We want to avoid this extra manual step.  Create an automatic action that do this. 

I know how to create an automatic action, but I do not know coding.  So I need that line of Python code that execute this. 

There is a button in the form view of Manufacturing order and I can see it uses method 'button_mark_done'.   How do I write the python expression that execute thios from an automatic action.

A video of how we confirm orders is found here. Jumpt to 3 minutes to see how orders are closed

https://drive.google.com/open?id=1-iuukpnL9Z1-SgjmnF4Id4AmhBzTyF2I&authuser=larsaam34%40gmail.com&usp=drive_fs

Avatar
Discard
Best Answer

Hello Lars,

I am not an expert in coding side, but please try the following.

model.search([('state', '=', 'to_close')]).button_mark_done()



Note: Cron will not work in case any of the records are not satisfying the condition to mark as done. For example, If lot/Serial number is enabled, but yet to generate, So in this case cron will throw a warning.. if all the to_close state records are satisfying all the condition to mark as done, then this cron will work without any issue.
Avatar
Discard
Author

Thanks a lot. But I was hoping to run this as an automatic action on the current record.
My action looks like this, but does not process the current record that change status. So very to close to get what we need, but not quite there yet.

https://drive.google.com/file/d/10IUucQ0BV9VSLJnMbCnklTfQILxkSntr/view?usp=sharing

Author

A solution might be to run the schedule action like every 5 minutes.

Best Answer

see below. Use this every day. Ignore the MO Type = Parent field, that's custom. 


Avatar
Discard
Author

Thank you for your answer. The code you use is exact the same as we have in the server action "Button Mark Done". I am not able to get it working in a automated action. Orders remain in status "To Close". Quite frustrating. We use V14.

Best Answer
for r in records.filtered(lambda x: x.state == ‘to_close’):                  

r.button_mark_done()

    

Avatar
Discard

I didn't check the button_mark_done() code but it seems is not calling wizards at all. So you can execute it over the record set. Nevertheless, with my approach, you can be sure that we don't call it from records of the record set that cannot be closed yet.

Author

This must also be run as a schedule action? For a scheduled action this code also works:
model.search([('state', '=', 'to_close')]).button_mark_done().

I was thinking an automatic action would be more efficient, since it only needs to be run, when a work order for is partly confirmed. It is not so freequent. Will be hours between every event. With a scheduled action it must be run like every 5 minutes to be OK for the flow.
But with an automatic action, triggered by Update of field State(mrp.production), it do not process the order that triggered the action.

You can run from automatic action as well. Using model directly is correct, nevertheless searching the whole model does not allow you to pre select a dataset

Best Answer

Have you tried using this Python Code:

records.action_button_mark_done()


Avatar
Discard
Author

Thank you Chris. But the result was a error:

Error:
Odoo Server Error

Traceback (most recent call last):
File "/home/odoo/src/odoo/odoo/addons/base/models/ir_http.py", line 237, in _dispatch
result = request.dispatch()
File "/home/odoo/src/odoo/odoo/http.py", line 685, in dispatch
result = self._call_function(**self.params)
File "/home/odoo/src/odoo/odoo/http.py", line 361, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/home/odoo/src/odoo/odoo/service/model.py", line 94, in wrapper
return f(dbname, *args, **kwargs)
File "/home/odoo/src/odoo/odoo/http.py", line 349, in checked_call
result = self.endpoint(*a, **kw)
File "/home/odoo/src/odoo/odoo/http.py", line 914, in __call__
return self.method(*args, **kw)
File "/home/odoo/src/odoo/odoo/http.py", line 533, in response_wrap
response = f(*args, **kw)
File "/home/odoo/src/odoo/addons/web/controllers/main.py", line 1392, in call_button
action = self._call_kw(model, method, args, kwargs)
File "/home/odoo/src/user/3rdparty/printnode_base/controllers/main.py", line 50, in _call_kw
return super(DataSetProxy, self)._call_kw(model, method, args, kwargs)
File "/home/odoo/src/odoo/addons/web/controllers/main.py", line 1380, in _call_kw
return call_kw(request.env[model], method, args, kwargs)
File "/home/odoo/src/odoo/odoo/api.py", line 400, in call_kw
model.flush()
File "/home/odoo/src/odoo/odoo/models.py", line 5473, in flush
self.recompute()
File "/home/odoo/src/odoo/odoo/models.py", line 5932, in recompute
process(field)
File "/home/odoo/src/odoo/odoo/models.py", line 5916, in process
field.recompute(recs)
File "/home/odoo/src/odoo/odoo/fields.py", line 1155, in recompute
self.compute_value(recs)
File "/home/odoo/src/odoo/odoo/fields.py", line 1177, in compute_value
records._compute_field_value(self)
File "/home/odoo/src/odoo/odoo/models.py", line 4080, in _compute_field_value
field.compute(self)
File "/home/odoo/src/odoo/odoo/fields.py", line 555, in _compute_related
record[self.name] = self._process_related(value[self.related_field.name])
File "/home/odoo/src/odoo/odoo/models.py", line 5712, in __setitem__
return self._fields[key].__set__(self, value)
File "/home/odoo/src/odoo/odoo/fields.py", line 1109, in __set__
self.write(protected_records, value)
File "/home/odoo/src/odoo/odoo/fields.py", line 1588, in write
records.env['ir.translation']._set_ids(
File "/home/odoo/src/odoo/odoo/addons/base/models/ir_translation.py", line 272, in _set_ids
self.sudo().create([{
File "<decorator-gen-58>", line 2, in create
File "/home/odoo/src/odoo/odoo/api.py", line 348, in _model_create_multi
return create(self, arg)
File "/home/odoo/src/odoo/odoo/addons/base/models/ir_translation.py", line 564, in create
self.flush()
File "/home/odoo/src/odoo/odoo/models.py", line 5473, in flush
self.recompute()
File "/home/odoo/src/odoo/odoo/models.py", line 5932, in recompute
process(field)
File "/home/odoo/src/odoo/odoo/models.py", line 5916, in process
field.recompute(recs)
File "/home/odoo/src/odoo/odoo/fields.py", line 1155, in recompute
self.compute_value(recs)
File "/home/odoo/src/odoo/odoo/fields.py", line 1177, in compute_value
records._compute_field_value(self)
File "/home/odoo/src/odoo/addons/base_automation/models/base_automation.py", line 378, in _compute_field_value
_compute_field_value.origin(self, field)
File "/home/odoo/src/odoo/odoo/models.py", line 4080, in _compute_field_value
field.compute(self)
File "/home/odoo/src/odoo/odoo/fields.py", line 555, in _compute_related
record[self.name] = self._process_related(value[self.related_field.name])
File "/home/odoo/src/odoo/odoo/models.py", line 5703, in __getitem__
return self._fields[key].__get__(self, type(self))
File "/home/odoo/src/odoo/odoo/fields.py", line 969, in __get__
self.recompute(record)
File "/home/odoo/src/odoo/odoo/fields.py", line 1155, in recompute
self.compute_value(recs)
File "/home/odoo/src/odoo/odoo/fields.py", line 1177, in compute_value
records._compute_field_value(self)
File "/home/odoo/src/odoo/addons/base_automation/models/base_automation.py", line 382, in _compute_field_value
action._process(records, domain_post=domain_post)
File "/home/odoo/src/odoo/addons/base_automation/models/base_automation.py", line 274, in _process
raise e
File "/home/odoo/src/odoo/addons/base_automation/models/base_automation.py", line 271, in _process
action_server.sudo().with_context(**ctx).run()
File "/home/odoo/src/odoo/odoo/addons/base/models/ir_actions.py", line 632, in run
res = runner(run_self, eval_context=eval_context)
File "/home/odoo/src/odoo/addons/website/models/ir_actions.py", line 61, in _run_action_code_multi
res = super(ServerAction, self)._run_action_code_multi(eval_context)
File "/home/odoo/src/odoo/odoo/addons/base/models/ir_actions.py", line 501, in _run_action_code_multi
safe_eval(self.code.strip(), eval_context, mode="exec", nocopy=True) # nocopy allows to return 'action'
File "/home/odoo/src/odoo/odoo/tools/safe_eval.py", line 347, in safe_eval
raise ValueError('%s: "%s" while evaluating\n%r' % (ustr(type(e)), ustr(e), expr))
Exception

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/home/odoo/src/odoo/odoo/http.py", line 641, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/home/odoo/src/odoo/odoo/http.py", line 317, in _handle_exception
raise exception.with_traceback(None) from new_cause
ValueError: <class 'AttributeError'>: "'mrp.production' object has no attribute 'action_button_mark_done'" while evaluating
"# Available variables:\n# - env: Odoo Environment on which the action is triggered\n# - model: Odoo Model of the record on which the action is triggered; is a void recordset\n# - record: record on which the action is triggered; may be void\n# - records: recordset of all records on which the action is triggered in multi-mode; may be void\n# - time, datetime, dateutil, timezone: useful Python libraries\n# - float_compare: Odoo function to compare floats based on specific precisions\n# - log: log(message, level='info'): logging function to record debug information in ir.logging table\n# - UserError: Warning Exception to use with raise\n# To return an action, assign: action = {...\nrecords.action_button_mark_done()"

Author

Running a schedule action every 5 minutes works. And is also OK in our process. A short timelag is not an issue. But automatic action seems more logic.

Chris, you cannot call action_button_mark_done because there is no python code with this method. Instead, there is a method button_mark_done() defined in the model that is callable.

Best Answer

Hello Lars Aam,

You Can Create Automated Action to set manufacturing order in status Done.

Find Example in comment.

I hope you are doing well.

For Example -

- Create an Automated action by adding name, model (Production Order as per your requirement), trigger (update as per your requirement), trigger fields(Status), Before Update domain (State = "progress"), filter domain (Status = "to_close") and Action to do ( Execute several actions as per your requirement )

- In the Actions Notebook below add the server action "Mark as Done".

- So when the order will change its state from "progress" to "to_close" our server action ( Mark as Done ) will be Triggered, and your order will be in the Done State.

I hope this will help you.

Thanks & Regards,
Email: odoo@aktivsoftware.com
Skype: kalpeshmaheshwari

Avatar
Discard
Author

Thank you for your answer. This was in fact the first I tried, before posting this question. It does not work. Order is not processed.
Difficuilt to understand why.

What works is a scheduled action with the code:
model.search([('state', '=', 'to_close')]).button_mark_done()

We are running this every 5 minutes, and that is OK for the business.

Best Answer

you can use the "Workflow" feature to set up automatic actions that change the status of a manufacturing order to "Done." Here are the general steps to set this up:

  1. Go to the "Manufacturing" module in Odoo and navigate to the "Manufacturing Orders" menu.

  2. Select the manufacturing order for which you want to set up the automatic action.

  3. Click on the "More" button and select "Workflow."

  4. In the "Workflow" menu, you can create a new workflow or edit an existing one.

  5. In the workflow, you can create a new "Transition" that changes the status of the manufacturing order from "In Progress" to "Done" when certain conditions are met.

  6. You can set up conditions for the transition by clicking on the "Conditions" button.

  7. In the conditions, you can set up triggers that automatically change the status of the manufacturing order to "Done" when certain actions are performed, such as when all the products have been produced or when the production is completed.

  8. Save the workflow and activate it.

Please note that these are general steps and the exact steps may vary depending on the version of Odoo you are using.

Avatar
Discard
Author

Thank you for your answer. Cannot find button "More" and Workflow. We run V14, so maybe that is for a later version.

Author

I cannot find a "More" button in a manufacturing order in Odoo16

Related Posts Replies Views Activity
0
Sep 21
2464
1
Sep 24
367
1
Aug 24
518
1
Jun 23
4311
0
Jun 23
897