# -*- encoding: utf-8 -*- ############################################################################## # # Odoo, Open Source Management Solution # # Author: Andrius Laukavičius. Copyright: JSC NOD Baltic # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as # published by the Free Software Foundation, either version 3 of the # License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . # ############################################################################## from openerp import models, api 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' # return datetime.now(self.get_timezone()).strftime(DATE_FORMAT) class SaleOrder(models.Model): _inherit = 'sale.order' ''' Timezone ''' def get_timezone(self): return timezone(self._context.get('tz') or self.env.user.tz) def _convert_str_to_datetime(self, date): return datetime.strptime(date,DEFAULT_SERVER_DATETIME_FORMAT) @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}) self.update_state() inv.signal_workflow('invoice_open') for picking in sale.picking_ids: picking.force_assign() picking.action_done() @api.multi def update_state(self): for order in self: order.write({'state': 'done'}) return True @api.multi def action_cancel(self): """ Cancel the sale order if it's in 'draft' or 'sent' state. """ for order in self: if order.state in ['draft', 'sent']: order.write({'state': 'cancel'}) return True