Skip to content

Commit

Permalink
[ADD] account_check: Support deposit and transfer checks from differe… (
Browse files Browse the repository at this point in the history
#126)

* [ADD] account_check: Support deposit and transfer checks from different currencies

* [ADD] account_check: Support deposit and transfer checks from currencies
different that the company.

* [ADD] account_check: Hide exchange information when delivered_third_check

* [IMP] deliverd third checks on other currency

* [IMP] improve code for checks in other currency

* [FIX] lint

* [IMP]
  • Loading branch information
jjscarafia committed Dec 17, 2018
1 parent 59852b2 commit 4f9399c
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 16 deletions.
6 changes: 5 additions & 1 deletion account_check/__openerp__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
##############################################################################
{
'name': 'Account Check Management',
'version': '9.0.1.25.0',
'version': '9.0.1.26.0',
'category': 'Accounting',
'summary': 'Accounting, Payment, Check, Third, Issue',
'author': "OpenERP Team de Localizacion Argentina,"
Expand All @@ -32,6 +32,10 @@
# 'account',
# for bank and cash menu and also for better usability
'account_payment_fix',
# TODO we should move field amount_company_currency to
# account_payment_fix so that we dont need to depend on
# account_payment_group
'account_payment_group',
],
'data': [
'data/account_payment_method_data.xml',
Expand Down
15 changes: 15 additions & 0 deletions account_check/migrations/9.0.1.26.0/post-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from openupgradelib import openupgrade
import logging

_logger = logging.getLogger(__name__)


@openupgrade.migrate()
def migrate(cr, version):

_logger.info('Setting inital values for amount_company_currency')
cr.execute("""
UPDATE account_check AS ac SET amount_company_currency = ac.amount
FROM res_company AS rc
WHERE rc.id = ac.company_id and ac.currency_id = rc.currency_id
""")
10 changes: 4 additions & 6 deletions account_check/models/account_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,14 +205,13 @@ class AccountCheck(models.Model):
readonly=True,
states={'draft': [('readonly', False)]}
)

amount = fields.Monetary(
currency_field='company_currency_id',
currency_field='currency_id',
readonly=True,
states={'draft': [('readonly', False)]}
)
amount_currency = fields.Monetary(
currency_field='currency_id',
amount_company_currency = fields.Monetary(
currency_field='company_currency_id',
readonly=True,
states={'draft': [('readonly', False)]},
)
Expand Down Expand Up @@ -642,8 +641,7 @@ def action_create_debit_note(
# 'product_id': self.product_id.id,
'name': name,
'account_id': account.id,
'price_unit': (
self.amount_currency and self.amount_currency or self.amount),
'price_unit': self.amount,
# 'invoice_id': invoice.id,
}

Expand Down
52 changes: 44 additions & 8 deletions account_check/models/account_payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# directory
##############################################################################
from openerp import fields, models, _, api
from openerp.exceptions import UserError
from openerp.exceptions import UserError, ValidationError
import logging
# import openerp.addons.decimal_precision as dp
_logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -158,12 +158,47 @@ def _compute_payment_method_description(self):

# on change methods

# @api.constrains('check_ids')
@api.onchange('amount_company_currency')
def _inverse_amount_company_currency(self):
# en v9 tenemos algun tipo de error en el orden en que se llama
# el inverse asi que lo desactivamos para cheques
self = self.filtered(
lambda x: x.payment_method_code != 'delivered_third_check')
return super(AccountPayment, self)._inverse_amount_company_currency()

@api.constrains('check_ids')
def set_checks_amounts(self):
for rec in self:
if rec.payment_method_code == 'delivered_third_check':
currency = rec.check_ids.mapped('currency_id')
if len(currency) > 1:
raise ValidationError(_(
'You are trying to deposit checks of difference'
' currencies, this functionality is not supported'))
elif len(currency) == 1:
rec.currency_id = currency.id
# si es una entrega de cheques de terceros y es en otra moneda
# a la de la cia, forzamos el importe en moneda de cia de los
# cheques originales
# por mismo error comentado en _inverse_amount_company_currency
# en v9 lo hacemos asi
if rec.currency_id != rec.company_currency_id:
rec.force_amount_company_currency = sum(
rec.check_ids.mapped('amount_company_currency'))

@api.onchange('check_ids', 'payment_method_code')
def onchange_checks(self):
# we only overwrite if payment method is delivered
if self.payment_method_code == 'delivered_third_check':
self.amount = sum(self.check_ids.mapped('amount'))
for rec in self:
# we only overwrite if payment method is delivered
if rec.payment_method_code == 'delivered_third_check':
rec.amount = sum(rec.check_ids.mapped('amount'))
currency = rec.check_ids.mapped('currency_id')
if len(currency) > 1:
raise ValidationError(_(
'You are trying to deposit checks of difference'
' currencies, this functionality is not supported'))
elif len(currency) == 1:
rec.currency_id = currency.id

@api.multi
@api.onchange('check_number')
Expand Down Expand Up @@ -287,10 +322,10 @@ def create_check(self, check_type, operation, bank):
'journal_id': self.journal_id.id,
'amount': self.amount,
'payment_date': self.check_payment_date,
# TODO arreglar que monto va de amount y cual de amount currency
# 'amount_currency': self.amount,
'currency_id': self.currency_id.id,
'amount_company_currency': self.amount_company_currency,
}

check = self.env['account.check'].create(check_vals)
self.check_ids = [(4, check.id, False)]
check._add_operation(
Expand Down Expand Up @@ -482,7 +517,8 @@ def post(self):
'Para mandar a proceso de firma debe definir número '
'de cheque en cada línea de pago.\n'
'* ID del pago: %s') % rec.id)
return super(AccountPayment, self).post()
res = super(AccountPayment, self).post()
return res

def _get_liquidity_move_line_vals(self, amount):
vals = super(AccountPayment, self)._get_liquidity_move_line_vals(
Expand Down
3 changes: 2 additions & 1 deletion account_check/views/account_check_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<field name="company_id" groups="base.group_multi_company"/>
<field name="state"/>
<field name="owner_name" invisible="context.get('default_type',False) != 'third_check'"/>
<field name="currency_id" invisible="1"/>
</tree>
</field>
</record>
Expand Down Expand Up @@ -73,7 +74,7 @@
<field name="bank_id"/>
<field name="number"/>
<field name="amount"/>
<field name="amount_currency" attrs="{'invisible': [('amount_currency', '=', 0.0)]}"/>
<field name="amount_company_currency"/>
</group>
<group>
<field name="state"/>
Expand Down
17 changes: 17 additions & 0 deletions account_check/views/account_payment_view.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>

<record id="view_account_payment2_form_inherited" model="ir.ui.view">
<field name="name">account.payment.form.inherited</field>
<field name="model">account.payment</field>
<field name="inherit_id" ref="account_payment_group.view_account_payment_form" />
<field name="arch" type="xml">
<label for="amount_company_currency" position="attributes">
<attribute name="attrs">{'invisible': ['|', ('other_currency', '=', False), ('payment_method_code', '=', 'delivered_third_check')]}</attribute>
</label>
<div name="amount_company_currency" position="attributes">
<attribute name="attrs">{'invisible': ['|', ('other_currency', '=', False), ('payment_method_code', '=', 'delivered_third_check')]}</attribute>
</div>
</field>
</record>

<!-- TODO inherit other form views also (like check printing module) -->
<record id="view_account_payment_form_inherited" model="ir.ui.view">
<field name="name">account.payment.form.inherited</field>
Expand Down Expand Up @@ -32,6 +47,7 @@
<field name="payment_date"/>
<field name="amount" sum="Total"/>
<field name="state" invisible="1"/>
<field name="currency_id" invisible="1"/>
</tree>
</field>
<field name="check_ids"
Expand All @@ -43,6 +59,7 @@
<field name="payment_date"/>
<field name="amount" sum="Total"/>
<field name="state" invisible="1"/>
<field name="currency_id" invisible="1"/>
</tree>
</field>
</group>
Expand Down

0 comments on commit 4f9399c

Please sign in to comment.