|
@@ -0,0 +1,59 @@
|
|
|
|
+# -*- 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 sale_order(models.Model):
|
|
|
|
+ _inherit = 'sale.order'
|
|
|
|
+
|
|
|
|
+ contado = fields.Boolean('Contado')
|
|
|
|
+ credito = fields.Boolean('Crédito')
|
|
|
|
+
|
|
|
|
+ _defaults = {
|
|
|
|
+ 'contado': True,
|
|
|
|
+ 'order_policy':'prepaid'
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @api.one
|
|
|
|
+ @api.onchange('contado')
|
|
|
|
+ def cambiar_estado_contado(self):
|
|
|
|
+ self.credito = not self.contado
|
|
|
|
+ if self.contado == True:
|
|
|
|
+ self.payment_term = False
|
|
|
|
+ self.order_policy = 'prepaid'
|
|
|
|
+
|
|
|
|
+ @api.one
|
|
|
|
+ @api.onchange('credito')
|
|
|
|
+ def cambiar_estado_credito(self):
|
|
|
|
+ self.contado = not self.credito
|
|
|
|
+ if self.credito == True:
|
|
|
|
+ self.order_policy = 'manual'
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ def _convert_str_to_datetime(self, date):
|
|
|
|
+ return datetime.strptime(date,DEFAULT_SERVER_DATETIME_FORMAT)
|
|
|
|
+
|
|
|
|
+ @api.multi
|
|
|
|
+ def create_invoice(self):
|
|
|
|
+ for sale in self:
|
|
|
|
+ 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,
|
|
|
|
+ '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
|