Browse Source

Move Voucher

SEBAS 1 year ago
commit
06a8a86bdb
10 changed files with 303 additions and 0 deletions
  1. 3 0
      __init__.py
  2. BIN
      __init__.pyc
  3. 25 0
      __openerp__.py
  4. 57 0
      i18n/en.po
  5. 71 0
      i18n/es.po
  6. 3 0
      models/__init__.py
  7. BIN
      models/__init__.pyc
  8. 124 0
      models/account_move.py
  9. BIN
      models/account_move.pyc
  10. 20 0
      views/account_move_view.xml

+ 3 - 0
__init__.py

@@ -0,0 +1,3 @@
+# -*- coding: utf-8 -*-
+import models
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

BIN
__init__.pyc


+ 25 - 0
__openerp__.py

@@ -0,0 +1,25 @@
+# -*- coding: utf-8 -*-
+{'active': False,
+    'author':  'ADHOC SA',
+    'website': 'www.adhoc.com.ar',
+    'license': 'AGPL-3',
+    'category': 'Accounting & Finance',
+    'data': [
+        'views/account_move_view.xml',
+    ],
+    'demo': [],
+    'depends': [
+        'account_voucher'
+    ],
+    'description': '''
+Account Move Voucher
+====================
+Create Vouchers from Account Move
+Creates a new residual field on account move
+Creates a method to pay moves with residual
+''',
+    'installable': True,
+    'name': 'Account Move Voucher',
+    'test': [],
+    'version': '8.0.1.2.0',
+ }

+ 57 - 0
i18n/en.po

@@ -0,0 +1,57 @@
+# Translation of Odoo Server.
+# This file contains the translation of the following modules:
+# * account_move_voucher
+# 
+# Translators:
+msgid ""
+msgstr ""
+"Project-Id-Version: odoo-addons (8.0)\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2015-10-22 13:44+0000\n"
+"PO-Revision-Date: 2015-10-01 15:15+0000\n"
+"Last-Translator: Juan Jose Scarafia <scarafia.juanjose@gmail.com>\n"
+"Language-Team: English (http://www.transifex.com/adhoc/ingadhoc-odoo-addons-8-0/language/en/)\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: \n"
+"Language: en\n"
+"Plural-Forms: nplurals=2; plural=(n != 1);\n"
+
+#. module: account_move_voucher
+#: model:ir.model,name:account_move_voucher.model_account_move
+msgid "Account Entry"
+msgstr "Account Entry"
+
+#. module: account_move_voucher
+#: view:account.move:account_move_voucher.view_move_form
+msgid "Create Payment Voucher"
+msgstr "Create Payment Voucher"
+
+#. module: account_move_voucher
+#: view:account.move:account_move_voucher.view_move_form
+msgid "Create Receipt Voucher"
+msgstr "Create Receipt Voucher"
+
+#. module: account_move_voucher
+#: code:addons/account_move_voucher/models/account_move.py:25
+#, python-format
+msgid "Payable Balance"
+msgstr "Payable Balance"
+
+#. module: account_move_voucher
+#: code:addons/account_move_voucher/models/account_move.py:86
+#, python-format
+msgid "Payment"
+msgstr "Payment"
+
+#. module: account_move_voucher
+#: code:addons/account_move_voucher/models/account_move.py:89
+#, python-format
+msgid "Receipt"
+msgstr "Receipt"
+
+#. module: account_move_voucher
+#: code:addons/account_move_voucher/models/account_move.py:18
+#, python-format
+msgid "Receivable Balance"
+msgstr "Receivable Balance"

+ 71 - 0
i18n/es.po

@@ -0,0 +1,71 @@
+# Translation of Odoo Server.
+# This file contains the translation of the following modules:
+# * account_move_voucher
+# 
+# Translators:
+# emiq2 <eq@ingadhoc.com>, 2016
+# Juan José Scarafía <scarafia.juanjose@gmail.com>, 2016
+msgid ""
+msgstr ""
+"Project-Id-Version: account-payment (8.0)\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2016-05-24 13:23+0000\n"
+"PO-Revision-Date: 2016-05-24 20:24+0000\n"
+"Last-Translator: Juan José Scarafía <scarafia.juanjose@gmail.com>\n"
+"Language-Team: Spanish (http://www.transifex.com/adhoc/ingadhoc-account-payment-8-0/language/es/)\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: \n"
+"Language: es\n"
+"Plural-Forms: nplurals=2; plural=(n != 1);\n"
+
+#. module: account_move_voucher
+#: model:ir.model,name:account_move_voucher.model_account_move
+msgid "Account Entry"
+msgstr "Asiento contable"
+
+#. module: account_move_voucher
+#: view:account.move:account_move_voucher.view_move_form
+msgid "Create Payment Voucher"
+msgstr "Crear Comprobante de Pago"
+
+#. module: account_move_voucher
+#: view:account.move:account_move_voucher.view_move_form
+msgid "Create Receipt Voucher"
+msgstr "Crear Recibo"
+
+#. module: account_move_voucher
+#: field:account.move,payable_residual:0
+#: code:addons/account_move_voucher/models/account_move.py:25
+#, python-format
+msgid "Payable Balance"
+msgstr "Saldo a Pagar"
+
+#. module: account_move_voucher
+#: code:addons/account_move_voucher/models/account_move.py:86
+#, python-format
+msgid "Payment"
+msgstr "Pago"
+
+#. module: account_move_voucher
+#: code:addons/account_move_voucher/models/account_move.py:89
+#, python-format
+msgid "Receipt"
+msgstr "Recibo"
+
+#. module: account_move_voucher
+#: field:account.move,receivable_residual:0
+#: code:addons/account_move_voucher/models/account_move.py:18
+#, python-format
+msgid "Receivable Balance"
+msgstr "Saldo a Cobrar"
+
+#. module: account_move_voucher
+#: help:account.move,payable_residual:0
+msgid "Remaining payable amount due."
+msgstr "Importe a pagar restante"
+
+#. module: account_move_voucher
+#: help:account.move,receivable_residual:0
+msgid "Remaining receivable amount due."
+msgstr "Importe a cobrar restante"

+ 3 - 0
models/__init__.py

@@ -0,0 +1,3 @@
+# -*- coding: utf-8 -*-
+import account_move
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

BIN
models/__init__.pyc


+ 124 - 0
models/account_move.py

@@ -0,0 +1,124 @@
+# -*- coding: utf-8 -*-
+from openerp import fields, models, api, _
+from openerp.exceptions import Warning
+import openerp.addons.decimal_precision as dp
+import logging
+_logger = logging.getLogger(__name__)
+
+
+class account_move(models.Model):
+    _inherit = 'account.move'
+
+    # residual_type = fields.Selection([
+    #     ('receivable', 'Receivable'),
+    #     ('payable', 'Payable'),
+    #     ],
+    #     string='Residual Type')
+    receivable_residual = fields.Float(
+        string=_('Receivable Balance'),
+        digits=dp.get_precision('Account'),
+        compute='_compute_residual',
+        # store=True,
+        help="Remaining receivable amount due."
+        )
+    payable_residual = fields.Float(
+        string=_('Payable Balance'),
+        digits=dp.get_precision('Account'),
+        compute='_compute_residual',
+        # store=True,
+        help="Remaining payable amount due."
+        )
+
+    @api.one
+    @api.depends(
+        'state',
+        'line_id.account_id.type',
+        'line_id.amount_residual',
+        # Fixes the fact that move_id.line_id.amount_residual, being not stored and old API, doesn't trigger recomputation
+        'line_id.reconcile_id',
+        # 'line_id.amount_residual_currency',
+        # 'line_id.currency_id',
+        'line_id.reconcile_partial_id.line_partial_ids',
+        # 'line_id.reconcile_partial_id.line_partial_ids.invoice.type',
+    )
+    def _compute_residual(self):
+        # TODO tal vez falta agregar lo de multi currency de donde lo sacamos
+        # de invoice
+        payable_residual = 0.0
+        receivable_residual = 0.0
+        # Each partial reconciliation is considered only once for each invoice
+        # it appears into,
+        # and its residual amount is divided by this number of invoices
+        partial_reconciliations_done = []
+        for line in self.sudo().line_id:
+            if line.account_id.type not in ('receivable', 'payable'):
+                continue
+            if line.reconcile_partial_id and line.reconcile_partial_id.id in partial_reconciliations_done:
+                continue
+            # Get the correct line residual amount
+            line_amount = line.amount_residual_currency if line.currency_id else line.amount_residual
+            # For partially reconciled lines, split the residual amount
+            if line.reconcile_partial_id:
+                r = line.reconcile_partial_id
+                line_amount = reduce(
+                    lambda y, t: (t.credit or 0.0) - (
+                        t.debit or 0.0) + y, r.line_partial_ids, 0.0)
+            if line.account_id.type == 'receivable':
+                receivable_residual += line_amount
+            else:
+                payable_residual += line_amount
+        self.payable_residual = max(payable_residual, 0.0)
+        self.receivable_residual = max(receivable_residual, 0.0)
+
+    @api.multi
+    def action_create_receipt_voucher(self):
+        return self.create_voucher('receipt')
+
+    @api.multi
+    def action_create_payment_voucher(self):
+        return self.create_voucher('payment')
+
+    @api.multi
+    def create_voucher(self, voucher_type):
+        # todo ver como podemos incorporar cobros, si es que tiene sentido
+        self.ensure_one()
+        if voucher_type == 'payment':
+            name = _('Payment')
+            residual_amount = self.payable_residual
+        else:
+            name = _('Receipt')
+            residual_amount = self.receivable_residual
+
+        view_id = self.env['ir.model.data'].xmlid_to_res_id(
+            'account_voucher.view_vendor_receipt_dialog_form')
+        voucher_context = self._context.copy()
+        voucher_context.update({
+                'payment_expected_currency': self.company_id.currency_id.id,
+                'default_partner_id': self.partner_id.id,
+                'default_amount': residual_amount,
+                # for compatibilit with other modules
+                'default_net_amount': residual_amount,
+                'default_reference': self.name,
+                'close_after_process': True,
+                # 'invoice_type': self.type,
+                # 'invoice_id': self.id,
+                'move_line_ids': self.line_id.filtered(
+                    lambda x: x.account_id.type in [
+                        'payable', 'receivable']).ids,
+                'default_type': voucher_type,
+                'default_company_id': self.company_id.id,
+                'type': 'voucher_type',
+                })
+        res = {
+            'name': name,
+            'view_mode': 'form',
+            'view_id': view_id,
+            'view_type': 'form',
+            'res_model': 'account.voucher',
+            'type': 'ir.actions.act_window',
+            'nodestroy': True,
+            'target': 'new',
+            'domain': '[]',
+            'context': voucher_context
+            }
+        return res

BIN
models/account_move.pyc


+ 20 - 0
views/account_move_view.xml

@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+<openerp>
+    <data>
+        <record id="view_move_form" model="ir.ui.view">
+            <field name="name">account.move.form</field>
+            <field name="model">account.move</field>
+            <field name="inherit_id" ref="account.view_move_form"/>
+            <field name="arch" type="xml">
+                <button name="button_validate" position="after">
+                    <button name="action_create_receipt_voucher" attrs="{'invisible':['|', ('state', '!=', 'posted'), ('receivable_residual', '=', 0.0)]}" string="Create Receipt Voucher" type="object" class="oe_highlight" groups="account.group_account_invoice"/>
+                    <button name="action_create_payment_voucher" attrs="{'invisible':['|', ('state', '!=', 'posted'), ('payable_residual', '=', 0.0)]}" string="Create Payment Voucher" type="object" class="oe_highlight" groups="account.group_account_invoice"/>
+                </button>
+                <field name="amount" position="after">
+                    <field name="receivable_residual" attrs="{'invisible': [('receivable_residual', '=', 0.0)]}"/>
+                    <field name="payable_residual" attrs="{'invisible': [('payable_residual', '=', 0.0)]}"/>
+                </field>
+            </field>
+        </record>
+    </data>
+</openerp>