notalentgeek

Auto Check Availability

Aug 17th, 2020 (edited)
685
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.66 KB | None | 0 0
  1. # Available variables:
  2. #  - env: Odoo Environment on which the action is triggered
  3. #  - model: Odoo Model of the record on which the action is triggered; is a
  4. #           void recordset
  5. #  - record: record on which the action is triggered; may be
  6. #            void
  7. #  - records: recordset of all records on which the action is triggered in
  8. #             multi-mode; may be void
  9. #  - time, datetime, dateutil, timezone: useful Python libraries
  10. #  - log: log(message, level='info'): logging function to record debug
  11. #         information in ir.logging table
  12. #  - Warning: Warning Exception to use with raise
  13. # To return an action, assign: action = {...}
  14.  
  15. delivery_orders_details_to_ready = []
  16.  
  17. delivery_orders = env['stock.picking'].search(
  18.     [
  19.         ('name', 'like', '%WH%'),
  20.         ('state', '=', 'confirmed'),
  21.     ],
  22.     limit=2000,
  23.     order='create_date asc',
  24. )
  25. env.cr.commit()
  26.  
  27. for delivery_order in delivery_orders:
  28.     delivery_order.action_assign()
  29.     env.cr.commit()
  30.  
  31.     if delivery_order.state == 'assigned':
  32.         delivery_orders_details_to_ready.append((
  33.             delivery_order.id,
  34.             delivery_order.name,
  35.         ))
  36.  
  37.     log(
  38.         ((
  39.             'Finished Running Check Availability on Delivery Order with ID: {} and Name: {}'
  40.         )).format(delivery_order.id, delivery_order.name),
  41.         level='info',
  42.     )
  43.     env.cr.commit()
  44.  
  45. log(
  46.     ((
  47.         'These delivery orders (ID and name pair) has just had their state '
  48.         'changed from "Waiting" to "Ready": {}, total: {}.'
  49.     )).format(
  50.         delivery_orders_details_to_ready,
  51.         len(delivery_orders_details_to_ready)
  52.     )
  53. )
  54. env.cr.commit()
  55.  
Add Comment
Please, Sign In to add comment