# -*- coding: utf-8 -*- from openerp import api, exceptions, fields, models, _ from pytz import timezone from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT, DEFAULT_SERVER_DATE_FORMAT from datetime import datetime,timedelta DATE_FORMAT = '%Y-%m-%d' class SaleOrder(models.Model): _inherit = "sale.order" commission_id = fields.Many2one('sale.commission', string='Regla de Comision') @api.multi def order_process_now(self): """ Confirms order and creates and validates invoice, confirms pickings. """ for sale in self: sale.action_button_confirm() inv_id = sale.action_invoice_create() if inv_id: inv = self.env['account.invoice'].browse(inv_id) date = self._convert_str_to_datetime(sale.date_order) date = date.strftime(DATE_FORMAT) inv.write({ 'date_invoice':date, 'supplier_invoice_number':self.invoice_number, 'contado':self.contado, 'credito':self.credito, 'commission_id':self.commission_id.id, }) self.update_state() inv.signal_workflow('invoice_open') for picking in sale.picking_ids: picking.force_assign() picking.action_done()