purchase_order.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. # -*- encoding: utf-8 -*-
  2. from openerp import models, api, fields
  3. from pytz import timezone
  4. from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT, DEFAULT_SERVER_DATE_FORMAT
  5. from datetime import datetime,timedelta
  6. DATE_FORMAT = '%Y-%m-%d'
  7. # import web_pdb; web_pdb.set_trace()
  8. class PurchaseOrder(models.Model):
  9. _inherit = 'purchase.order'
  10. _name = 'purchase.order'
  11. invoice_number = fields.Char('Numero de Factura')
  12. ''' Timezone '''
  13. def get_timezone(self):
  14. return timezone(self._context.get('tz') or self.env.user.tz)
  15. def _convert_str_to_datetime(self, date):
  16. return datetime.strptime(date,DEFAULT_SERVER_DATETIME_FORMAT)
  17. @api.multi
  18. def purchase_process_now(self):
  19. """
  20. Confirms order and creates and validates invoice, confirms pickings.
  21. """
  22. for purchase in self:
  23. inv_id = purchase.action_invoice_create()
  24. if inv_id:
  25. inv = self.env['account.invoice'].browse(inv_id)
  26. date = self._convert_str_to_datetime(purchase.date_order)
  27. date = date.strftime(DATE_FORMAT)
  28. inv.write({
  29. 'date_invoice':date,
  30. 'supplier_invoice_number':self.invoice_number,
  31. })
  32. inv.signal_workflow('invoice_open')
  33. purchase.action_picking_create()
  34. for picking in purchase.picking_ids:
  35. picking.force_assign()
  36. picking.action_done()
  37. purchase.wkf_po_done()
  38. class PurchaseOrderLine(models.Model):
  39. _inherit = 'purchase.order.line'
  40. _name = 'purchase.order.line'
  41. amount_total = fields.Float(compute='_calculate_total_purchase_line',string='Total',default=0.0)
  42. @api.depends('price_unit','product_qty')
  43. def _calculate_total_purchase_line(self):
  44. for line in self:
  45. line.amount_total = line.product_qty * (line.price_unit)
  46. # class AccountInvoice(models.Model):
  47. # _inherit = 'account.invoice'
  48. # _name = 'account.invoice'
  49. #
  50. # @api.one
  51. # @api.onchange('credito')
  52. # def cambiar_estado_credito(self):
  53. # self.contado = not self.credito
  54. #
  55. # @api.one
  56. # @api.onchange('contado')
  57. # def cambiar_estado_contado(self):
  58. # self.credito = not self.contado