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.

55 lines
2.3 KiB

  1. # -*- coding: utf-8 -*-
  2. # This file is part of OpenERP. The COPYRIGHT file at the top level of
  3. # this module contains the full copyright notices and license terms.
  4. from openerp import models, SUPERUSER_ID
  5. class POSOrder(models.Model):
  6. _inherit = "pos.order"
  7. def _create_account_move_line(self, cr, uid, ids, session=None,
  8. move_id=None, context=None):
  9. to_ret = super(POSOrder, self)._create_account_move_line(
  10. cr, uid, ids, session=session, move_id=move_id, context=context)
  11. account_def = self.pool.get('ir.property').get(
  12. cr, uid, 'property_account_receivable', 'res.partner')
  13. grouped_data = {}
  14. for order in self.browse(cr, SUPERUSER_ID, ids, context=context):
  15. current_company = order.sale_journal.company_id
  16. order_account = (
  17. order.partner_id and
  18. order.partner_id.property_account_receivable and
  19. order.partner_id.property_account_receivable.id or
  20. account_def and account_def.id or
  21. current_company.account_receivable.id
  22. )
  23. debit = ((order.amount_total > 0) and order.amount_total) or 0.0
  24. key = (order.partner_id.id, order_account, debit > 0)
  25. grouped_data.setdefault(key, [])
  26. for each in order.statement_ids:
  27. if each.account_id.id != order_account:
  28. continue
  29. for line in each.journal_entry_id.line_id:
  30. if (line.account_id.id == order_account and
  31. line.state == 'valid'):
  32. grouped_data[key].append(line.id)
  33. for key, value in grouped_data.iteritems():
  34. for line in order.account_move.line_id:
  35. if (line.partner_id.id == key[0] and
  36. line.account_id.id == key[1] and
  37. (line.debit > 0) == key[2] and
  38. line.state == 'valid'):
  39. grouped_data[key].append(line.id)
  40. break
  41. for key, value in grouped_data.iteritems():
  42. if not value:
  43. continue
  44. self.pool.get('account.move.line').reconcile_partial(
  45. cr, SUPERUSER_ID, value)
  46. return to_ret