diff --git a/pos_trade_receivable_autoreconcile/README.rst b/pos_trade_receivable_autoreconcile/README.rst new file mode 100644 index 00000000..e0f67d76 --- /dev/null +++ b/pos_trade_receivable_autoreconcile/README.rst @@ -0,0 +1,54 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :alt: License: AGPL-3 + +POS Trade Receivable Autoreconcile +================================== + +This module reconciles "Trade Receivable" record created on Customer account +with Payments made by this customer. + +Example: + +* Product costs 8EUR but customer pays 10EUR by cash getting 2EUR in return. +In accounting it looks like this: +1) D: cash: 10 +2) C: account_receivable: 10 + +3) D: account_receivable: 2 +4) C: cash: 2 + +* When closing & validating a session system would create "Trade Receivable" +counterpart like this: +5) D: account_receivable: 8 +6) C: income_account: 8 + +When this module is installed 2), 3) and 5) items would be reconciled when +closing a session. + +Usage +===== + +* Install the module. No configuration needed. + +Credits +======= + +Contributors +------------ + +* Andrius Preimantas + +Maintainer +---------- + +.. image:: http://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: http://odoo-community.org + +This module is maintained by the OCA. + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +To contribute to this module, please visit http://odoo-community.org. diff --git a/pos_trade_receivable_autoreconcile/__init__.py b/pos_trade_receivable_autoreconcile/__init__.py new file mode 100644 index 00000000..43414012 --- /dev/null +++ b/pos_trade_receivable_autoreconcile/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# This file is part of OpenERP. The COPYRIGHT file at the top level of +# this module contains the full copyright notices and license terms. + +from . import model diff --git a/pos_trade_receivable_autoreconcile/__openerp__.py b/pos_trade_receivable_autoreconcile/__openerp__.py new file mode 100644 index 00000000..6244dc30 --- /dev/null +++ b/pos_trade_receivable_autoreconcile/__openerp__.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- +# This file is part of OpenERP. The COPYRIGHT file at the top level of +# this module contains the full copyright notices and license terms. + +{ + 'name': 'POS Trade Receivable Autoreconcile', + 'version': '0.1', + 'author': 'Versada UAB', + 'category': 'Other', + 'website': 'http://www.versada.lt', + 'depends': [ + 'point_of_sale', + ], + 'data': [ + ], + 'installable': True, + 'application': False, +} diff --git a/pos_trade_receivable_autoreconcile/model/__init__.py b/pos_trade_receivable_autoreconcile/model/__init__.py new file mode 100644 index 00000000..e284389e --- /dev/null +++ b/pos_trade_receivable_autoreconcile/model/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# This file is part of OpenERP. The COPYRIGHT file at the top level of +# this module contains the full copyright notices and license terms. + +from . import point_of_sale diff --git a/pos_trade_receivable_autoreconcile/model/point_of_sale.py b/pos_trade_receivable_autoreconcile/model/point_of_sale.py new file mode 100644 index 00000000..261a476b --- /dev/null +++ b/pos_trade_receivable_autoreconcile/model/point_of_sale.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# This file is part of OpenERP. The COPYRIGHT file at the top level of +# this module contains the full copyright notices and license terms. + +from openerp import models + + +class POSOrder(models.Model): + _inherit = "pos.order" + + def _create_account_move_line(self, cr, uid, ids, session=None, + move_id=None, context=None): + to_ret = super(POSOrder, self)._create_account_move_line( + cr, uid, ids, session=session, move_id=move_id, context=context) + + account_def = self.pool.get('ir.property').get( + cr, uid, 'property_account_receivable', 'res.partner') + + grouped_data = {} + + for order in self.browse(cr, uid, ids, context=context): + current_company = order.sale_journal.company_id + order_account = ( + order.partner_id and + order.partner_id.property_account_receivable and + order.partner_id.property_account_receivable.id or + account_def and account_def.id or + current_company.account_receivable.id + ) + debit = ((order.amount_total > 0) and order.amount_total) or 0.0 + key = (order.partner_id.id, order_account, debit > 0) + grouped_data.setdefault(key, []) + for each in order.statement_ids: + if each.account_id.id != order_account: + continue + + for line in each.journal_entry_id.line_id: + if line.account_id.id == order_account: + grouped_data[key].append(line.id) + for key, value in grouped_data.iteritems(): + for line in order.account_move.line_id: + if line.account_id.id == key[1] and line.partner_id.id == key[0]: + grouped_data[key].append(line.id) + break + for key, value in grouped_data.iteritems(): + self.pool.get('account.move.line').reconcile_partial(cr, uid, value) + + return to_ret