sale_order.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # -*- coding: utf-8 -*-
  2. from openerp import models, fields, api
  3. class SaleOrder(models.Model):
  4. _inherit = 'sale.order'
  5. is_delivery = fields.Boolean(string='Delivery?')
  6. delivery_type = fields.Selection([
  7. ('local', 'Local'),
  8. ('envio', 'Envio al Interior')],
  9. string='Tipo de delivery', default='local')
  10. @api.multi
  11. def order_process_now(self):
  12. """
  13. Confirms order and creates and validates invoice, confirms pickings.
  14. """
  15. for sale in self:
  16. sale.action_button_confirm()
  17. inv_id = sale.action_invoice_create()
  18. if inv_id:
  19. inv = self.env['account.invoice'].browse(inv_id)
  20. inv.write({
  21. 'is_delivery':self.is_delivery,
  22. 'delivery_type':self.delivery_type,
  23. })
  24. self.update_state()
  25. inv.signal_workflow('invoice_open')
  26. for picking in sale.picking_ids:
  27. picking.force_assign()
  28. picking.action_done()
  29. @api.multi
  30. def update_state(self):
  31. for order in self:
  32. order.write({'state': 'done'})
  33. return True
  34. class AccountInvoice(models.Model):
  35. _inherit = 'account.invoice'
  36. is_delivery = fields.Boolean(string='Delivery?')
  37. delivery_type = fields.Selection([
  38. ('local', 'Local'),
  39. ('envio', 'Envio al Interior')],
  40. string='Tipo de delivery', default='local')