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.

74 lines
3.1 KiB

  1. # -*- coding: 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. # pylint: disable=R8110
  26. def _create_account_move_line(self, cr, uid, ids, session=None,
  27. move_id=None, context=None):
  28. to_ret = super(POSOrder, self)._create_account_move_line(
  29. cr, uid, ids, session=session, move_id=move_id, context=context)
  30. account_def = self.pool.get('ir.property').get(
  31. cr, uid, 'property_account_receivable', 'res.partner')
  32. grouped_data = {}
  33. for order in self.browse(cr, uid, ids, context=context):
  34. current_company = order.sale_journal.company_id
  35. order_account = (
  36. order.partner_id and
  37. order.partner_id.property_account_receivable and
  38. order.partner_id.property_account_receivable.id or
  39. account_def and account_def.id or
  40. current_company.account_receivable.id
  41. )
  42. debit = ((order.amount_total > 0) and order.amount_total) or 0.0
  43. key = (order.partner_id.id, order_account, debit > 0)
  44. grouped_data.setdefault(key, [])
  45. for each in order.statement_ids:
  46. if each.account_id.id != order_account:
  47. continue
  48. for line in each.journal_entry_id.line_id:
  49. if (line.account_id.id == order_account and
  50. line.state == 'valid'):
  51. grouped_data[key].append(line.id)
  52. for key, value in grouped_data.iteritems():
  53. for line in order.account_move.line_id:
  54. if (line.partner_id.id == key[0] and
  55. line.account_id.id == key[1] and
  56. (line.debit > 0) == key[2] and
  57. line.state == 'valid'):
  58. grouped_data[key].append(line.id)
  59. break
  60. for key, value in grouped_data.iteritems():
  61. if not value:
  62. continue
  63. self.pool.get('account.move.line').reconcile_partial(
  64. cr, uid, value)
  65. return to_ret