You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
3.1 KiB

  1. # -*- encoding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # OpenERP, Open Source Management Solution
  5. # This module copyright (C) 2015 UAB Versada
  6. # (<http://www.versada.lt>).
  7. #
  8. # This program is free software: you can redistribute it and/or modify
  9. # it under the terms of the GNU Affero General Public License as
  10. # published by the Free Software Foundation, either version 3 of the
  11. # License, or (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU Affero General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU Affero General Public License
  19. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. #
  21. ##############################################################################
  22. from openerp import models
  23. class POSOrder(models.Model):
  24. _inherit = "pos.order"
  25. def _create_account_move_line(self, cr, uid, ids, session=None,
  26. move_id=None, context=None):
  27. to_ret = super(POSOrder, self)._create_account_move_line(
  28. cr, uid, ids, session=session, move_id=move_id, context=context)
  29. account_def = self.pool.get('ir.property').get(
  30. cr, uid, 'property_account_receivable', 'res.partner')
  31. grouped_data = {}
  32. for order in self.browse(cr, uid, ids, context=context):
  33. current_company = order.sale_journal.company_id
  34. order_account = (
  35. order.partner_id and
  36. order.partner_id.property_account_receivable and
  37. order.partner_id.property_account_receivable.id or
  38. account_def and account_def.id or
  39. current_company.account_receivable.id
  40. )
  41. debit = ((order.amount_total > 0) and order.amount_total) or 0.0
  42. key = (order.partner_id.id, order_account, debit > 0)
  43. grouped_data.setdefault(key, [])
  44. for each in order.statement_ids:
  45. if each.account_id.id != order_account:
  46. continue
  47. for line in each.journal_entry_id.line_id:
  48. if (line.account_id.id == order_account and
  49. line.state == 'valid'):
  50. grouped_data[key].append(line.id)
  51. for key, value in grouped_data.iteritems():
  52. for line in order.account_move.line_id:
  53. if (line.partner_id.id == key[0] and
  54. line.account_id.id == key[1] and
  55. (line.debit > 0) == key[2] and
  56. line.state == 'valid'):
  57. grouped_data[key].append(line.id)
  58. break
  59. for key, value in grouped_data.iteritems():
  60. if not value:
  61. continue
  62. self.pool.get('account.move.line').reconcile_partial(
  63. cr, uid, value)
  64. return to_ret