# -*- encoding: utf-8 -*- from openerp import models, api, fields 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' # import web_pdb; web_pdb.set_trace() class PurchaseOrder(models.Model): _inherit = 'purchase.order' _name = 'purchase.order' invoice_number = fields.Char('Numero de Factura') ''' 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 purchase_process_now(self): """ Confirms order and creates and validates invoice, confirms pickings. """ for purchase in self: inv_id = purchase.action_invoice_create() if inv_id: inv = self.env['account.invoice'].browse(inv_id) date = self._convert_str_to_datetime(purchase.date_order) date = date.strftime(DATE_FORMAT) inv.write({ 'date_invoice':date, 'supplier_invoice_number':self.invoice_number, }) inv.signal_workflow('invoice_open') purchase.action_picking_create() for picking in purchase.picking_ids: picking.force_assign() picking.action_done() purchase.wkf_po_done() class PurchaseOrderLine(models.Model): _inherit = 'purchase.order.line' _name = 'purchase.order.line' amount_total = fields.Float(compute='_calculate_total_purchase_line',string='Total',default=0.0) @api.depends('price_unit','product_qty') def _calculate_total_purchase_line(self): for line in self: line.amount_total = line.product_qty * (line.price_unit) # class AccountInvoice(models.Model): # _inherit = 'account.invoice' # _name = 'account.invoice' # # @api.one # @api.onchange('credito') # def cambiar_estado_credito(self): # self.contado = not self.credito # # @api.one # @api.onchange('contado') # def cambiar_estado_contado(self): # self.credito = not self.contado