account_invoice_date.py 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. # -*- coding: utf-8 -*-
  2. from openerp import api, fields, models
  3. from openerp.exceptions import except_orm
  4. from datetime import datetime, timedelta
  5. from openerp.tools import DEFAULT_SERVER_DATE_FORMAT
  6. from dateutil.relativedelta import relativedelta
  7. class AccountInvoice(models.Model):
  8. _inherit = 'account.invoice'
  9. date_emision = fields.Date("Fecha de Emisión")
  10. # def sale_convert_str_to_datetime(self, date):
  11. # return datetime.strptime(date, DEFAULT_SERVER_DATE_FORMAT)
  12. #
  13. # @api.model
  14. # def getSaleOrder(self,idOrder):
  15. # return[{
  16. # 'id': order.id,
  17. # 'dateOrder': order.date_order.split(" ")[0],
  18. # 'dateQuota': order.date_emision or order.date_order.split(" ")[0],
  19. # } for order in self.env['sale.order'].browse(idOrder)]
  20. # @api.model
  21. # def getSaleOrderInterest(self,idOrder):
  22. # termConfig = self.env['accont.payments.term.config'].search([('compute', '=', True)])
  23. # if (not termConfig):
  24. # return []
  25. #
  26. # saleOrder = self.env['sale.order'].browse(idOrder)
  27. # if (not saleOrder):
  28. # return []
  29. # dateSale = self.sale_convert_str_to_datetime(saleOrder.date_order.split(" ")[0])
  30. # datefirst = self.sale_convert_str_to_datetime(saleOrder.date_quota or saleOrder.date_order.split(" ")[0])
  31. # daysDiference = datefirst - dateSale
  32. #
  33. # orderLine = self.env['sale.order.line'].search([('order_id', '=', idOrder),('is_interest','=',True)])
  34. # amountInteres = orderLine.price_subtotal or 0
  35. #
  36. # return [{
  37. # 'id': order.id,
  38. # 'amountTotal': (order.amount_total - amountInteres),
  39. # 'dateOrder': order.date_order.split(" ")[0],
  40. # 'dateQuota': order.date_quota or order.date_order.split(" ")[0],
  41. # 'amountInteres': round(daysDiference.days * ((order.amount_total - amountInteres) * (termConfig.interest_rate / 100)),order.pricelist_id.currency_id.decimal_places),
  42. # 'differenceDay': daysDiference.days,
  43. # 'messageDefault': termConfig.message_default,
  44. # 'currency': {
  45. # 'id': order.pricelist_id.currency_id.id,
  46. # 'symbol': order.pricelist_id.currency_id.symbol,
  47. # 'decimalSeparator': order.pricelist_id.currency_id.decimal_separator,
  48. # 'decimalPlaces': order.pricelist_id.currency_id.decimal_places,
  49. # 'thousandsSeparator': order.pricelist_id.currency_id.thousands_separator,
  50. # }
  51. # } for order in saleOrder]
  52. # ''' Discount '''
  53. # @api.model
  54. # def account_Sale_line_add_discount(self,idOrder, newAmount):
  55. # saleOrder = self.env['sale.order'].browse(idOrder)
  56. # if (not saleOrder):
  57. # return {'state': False }
  58. #
  59. # discount = abs(saleOrder.amount_total - newAmount)
  60. #
  61. # discountLine = {
  62. # 'order_id': saleOrder.id,
  63. # 'name':"DESCUENTO APLICADO",
  64. # 'price_unit': - discount,
  65. # 'price_subtotal': - discount,
  66. # }
  67. #
  68. # line = self.env['sale.order.line'].create(discountLine)
  69. # if (not line):
  70. # return { 'state': False }
  71. #
  72. # return { 'state': True }
  73. # ''' Interest '''
  74. # @api.model
  75. # def account_sale_line_interest(self, values):
  76. # interestLine = {
  77. # 'order_id': values['saleId'],
  78. # 'name':"Cambio de fecha de vencimiento, Diferencia("+str(values['differenceDay'])+") días.",
  79. # 'price_unit':values['amountInteres'],
  80. # 'price_subtotal':values['amountInteres'],
  81. # 'is_interest': True
  82. # }
  83. #
  84. # saleLine = self.env['sale.order.line'].search([('order_id', '=', values['saleId']),('is_interest','=',True)])
  85. #
  86. # if (not saleLine):
  87. # if (values['amountInteres'] <= 0):
  88. # return { 'state': True }
  89. #
  90. # saleLine.create(interestLine)
  91. # return { 'state': True }
  92. #
  93. # if (values['amountInteres'] <= 0):
  94. # saleLine.unlink()
  95. # return { 'state': True }
  96. #
  97. # saleLine.write(interestLine)
  98. # return { 'state': True }
  99. #
  100. # @api.model
  101. # def calculatePaymentTermSaleOrder(self, values):
  102. # order = self.env['sale.order'].browse(values['orderId'])
  103. #
  104. # if (not order):
  105. # return False
  106. #
  107. # dateSale = self.sale_convert_str_to_datetime(order.date_order.split(" ")[0])
  108. # datefirst = self.sale_convert_str_to_datetime(order.date_quota or order.date_order.split(" ")[0])
  109. #
  110. # amountTotal = order.amount_total
  111. # amountPayments = values['amountPayments']
  112. # amountResidual = amountTotal - amountPayments
  113. # cuotaCant = (amountResidual /values['amountCuota'])
  114. #
  115. # if (amountPayments > 0):
  116. # cuotaCant +=1
  117. #
  118. # termCalculator = []
  119. #
  120. # cuotaTotal= int(cuotaCant) if ((cuotaCant - int(cuotaCant)) <= 0) else int(cuotaCant)+1
  121. #
  122. # termType = self.env['account.payment.term.type'].browse(values['typeTerm'])
  123. # if (not termType):
  124. # return False
  125. #
  126. # numberCuota = 0
  127. # for cuota in xrange(int(cuotaCant)):
  128. # numberCuota = cuota+1
  129. # amount = values['amountCuota']
  130. # adddaysMaturity = datefirst - dateSale
  131. # date = datefirst
  132. #
  133. # if (numberCuota == 1 and (amountPayments > 0)):
  134. # amount = amountPayments
  135. # if (adddaysMaturity.days > 0):
  136. # adddaysMaturity = dateSale - dateSale
  137. # date = dateSale
  138. #
  139. # amountTotal -= amount
  140. #
  141. # termCalculator.append({
  142. # 'number' : numberCuota,
  143. # 'cuotaNumber': str(numberCuota)+"/"+str(cuotaTotal),
  144. # 'date': date.strftime(DEFAULT_SERVER_DATE_FORMAT),
  145. # 'amount': amount,
  146. # 'days': adddaysMaturity.days,
  147. # 'value': 'fixed' if (numberCuota < cuotaTotal) else 'balance'
  148. # })
  149. #
  150. # days = datefirst - dateSale
  151. # if(numberCuota == 1 and (amountPayments > 0) and days.days > 0 ):
  152. # continue
  153. #
  154. # if (termType.type_calculation == 'month' ):
  155. # datefirst += relativedelta(months=termType.qty_add)
  156. # else :
  157. # datefirst += timedelta(days=termType.qty_add)
  158. #
  159. # if (amountTotal > 0 ):
  160. # numberCuota +=1
  161. # adddaysMaturity = datefirst - dateSale
  162. #
  163. # termCalculator.append({
  164. # 'number' : numberCuota,
  165. # 'cuotaNumber': str(numberCuota)+"/"+str(cuotaTotal),
  166. # 'date': datefirst.strftime(DEFAULT_SERVER_DATE_FORMAT),
  167. # 'amount': amountTotal,
  168. # 'days': adddaysMaturity.days,
  169. # 'value': 'fixed' if (numberCuota < cuotaTotal) else 'balance'
  170. # })
  171. #
  172. # return termCalculator
  173. #
  174. # ''' Payments Term '''
  175. # @api.model
  176. # def accountPaymentTermConfiguratorSale(self, values, orderId):
  177. # resUser = self.env.user
  178. # if (not resUser):
  179. # return {
  180. # 'state': False,
  181. # 'message': 'No fue posible localizar el usuario.'
  182. # }
  183. #
  184. # term = self.env['account.payment.term'].search([('config', '=', True),('user_term', '=', resUser.id),('type_operation', '=', 'sale')])
  185. # if (term):
  186. # term.unlink()
  187. #
  188. # line = []
  189. # for configTerm in values:
  190. # line.append([0,False,{
  191. # 'payment_id': term.id,
  192. # 'value': configTerm['value'],
  193. # 'days': configTerm['days'],
  194. # 'value_amount': configTerm['amount'] if (configTerm['value'] == 'fixed') else 0
  195. # }])
  196. #
  197. # term = self.env['account.payment.term'].create({
  198. # 'name': 'Plazos Configurables %s - %s'%('Ventas', resUser.name),
  199. # 'type_operation': 'sale',
  200. # 'user_term': resUser.id,
  201. # 'config': True,
  202. # 'line_ids': line,
  203. # })
  204. #
  205. # ''' Actualizar condiciones de pago en la venta '''
  206. #
  207. # order = self.env['sale.order'].browse(orderId)
  208. # if (order):
  209. # order.write({'payment_term': term.id})
  210. #
  211. # return {
  212. # 'state': True,
  213. # 'message': 'Condiciones de pago configurado con éxito'
  214. # }