12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- # -*- encoding: utf-8 -*-
- from openerp import models, fields, api, _
- from openerp.exceptions import Warning
- 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 purchase_order(models.Model):
- _inherit = 'purchase.order'
- contado = fields.Boolean('Contado')
- credito = fields.Boolean('Crédito')
- _defaults = {
- 'contado': True
- }
- @api.one
- @api.onchange('contado')
- def cambiar_estado_contado(self):
- self.credito = not self.contado
- if self.contado == True:
- self.payment_term = False
- @api.one
- @api.onchange('credito')
- def cambiar_estado_credito(self):
- self.contado = not self.credito
- def _convert_str_to_datetime(self, date):
- return datetime.strptime(date,DEFAULT_SERVER_DATETIME_FORMAT)
- @api.model
- def action_invoice_create(self):
- for purchase in self:
- inv_id = super(purchase_order, self).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,
- 'contado':self.contado,
- 'credito':self.credito
- })
- self.update_state()
- @api.multi
- def update_state(self):
- for order in self:
- order.write({'state': 'done'})
- return True
|