sale_order.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. # -*- coding: utf-8 -*-
  2. from openerp import api, exceptions, fields, models, _
  3. from pytz import timezone
  4. from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT, DEFAULT_SERVER_DATE_FORMAT
  5. from datetime import datetime,timedelta
  6. DATE_FORMAT = '%Y-%m-%d'
  7. class SaleOrder(models.Model):
  8. _inherit = "sale.order"
  9. commission_id = fields.Many2one('sale.commission', string='Regla de Comision')
  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. date = self._convert_str_to_datetime(sale.date_order)
  21. date = date.strftime(DATE_FORMAT)
  22. inv.write({
  23. 'date_invoice':date,
  24. 'supplier_invoice_number':self.invoice_number,
  25. 'contado':self.contado,
  26. 'credito':self.credito,
  27. 'commission_id':self.commission_id.id,
  28. })
  29. self.update_state()
  30. inv.signal_workflow('invoice_open')
  31. for picking in sale.picking_ids:
  32. picking.force_assign()
  33. picking.action_done()