Skip to content

Commit

Permalink
Merge branch 'release/3.4.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
tarunbhardwaj committed Jun 3, 2015
2 parents 2450def + 7c88c3a commit 8806aaa
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 2 deletions.
9 changes: 9 additions & 0 deletions tests/test_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ def test_0010_test_manual_transaction(self):
with Transaction().set_context({'company': self.company.id}):
transaction, = self.PaymentGatewayTransaction.create([{
'party': self.party.id,
'credit_account': self.party.account_receivable.id,
'address': self.party.addresses[0].id,
'gateway': gateway.id,
'amount': 400,
Expand Down Expand Up @@ -226,6 +227,7 @@ def test_0210_test_dummy_gateway(self):
}])
transaction, = self.PaymentGatewayTransaction.create([{
'party': self.party.id,
'credit_account': self.party.account_receivable.id,
'address': self.party.addresses[0].id,
'gateway': gateway.id,
'amount': 400,
Expand Down Expand Up @@ -253,6 +255,7 @@ def test_0220_test_dummy_gateway(self):
}])
transaction, = self.PaymentGatewayTransaction.create([{
'party': self.party.id,
'credit_account': self.party.account_receivable.id,
'address': self.party.addresses[0].id,
'gateway': gateway.id,
'amount': 400,
Expand Down Expand Up @@ -323,6 +326,7 @@ def test_0220_test_dummy_gateway_authorize_fail(self):
}])
transaction, = self.PaymentGatewayTransaction.create([{
'party': self.party.id,
'credit_account': self.party.account_receivable.id,
'address': self.party.addresses[0].id,
'gateway': gateway.id,
'amount': 400,
Expand Down Expand Up @@ -352,6 +356,7 @@ def test_0220_test_dummy_gateway_capture(self):
}])
transaction, = self.PaymentGatewayTransaction.create([{
'party': self.party.id,
'credit_account': self.party.account_receivable.id,
'address': self.party.addresses[0].id,
'gateway': gateway.id,
'amount': 400,
Expand Down Expand Up @@ -383,6 +388,7 @@ def test_0220_test_dummy_gateway_capture_fail(self):
}])
transaction, = self.PaymentGatewayTransaction.create([{
'party': self.party.id,
'credit_account': self.party.account_receivable.id,
'address': self.party.addresses[0].id,
'gateway': gateway.id,
'amount': 400,
Expand Down Expand Up @@ -411,6 +417,7 @@ def test_0230_manual_gateway_auth_settle(self):
with Transaction().set_context({'company': self.company.id}):
transaction, = self.PaymentGatewayTransaction.create([{
'party': self.party.id,
'credit_account': self.party.account_receivable.id,
'address': self.party.addresses[0].id,
'gateway': gateway.id,
'amount': 400,
Expand Down Expand Up @@ -454,6 +461,7 @@ def test_0240_manual_gateway_capture(self):
with Transaction().set_context({'company': self.company.id}):
transaction, = self.PaymentGatewayTransaction.create([{
'party': self.party.id,
'credit_account': self.party.account_receivable.id,
'address': self.party.addresses[0].id,
'gateway': gateway.id,
'amount': 400,
Expand Down Expand Up @@ -517,6 +525,7 @@ def test_0260_test_dummy_delete_move(self):

transaction, = self.PaymentGatewayTransaction.create([{
'party': self.party.id,
'credit_account': self.party.account_receivable.id,
'address': self.party.addresses[0].id,
'gateway': gateway.id,
'amount': 400,
Expand Down
80 changes: 79 additions & 1 deletion transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
from uuid import uuid4
from decimal import Decimal
from datetime import datetime
from sql.functions import Trim, Substring
from sql.operators import Concat

import yaml
from trytond.pool import Pool, PoolMeta
Expand All @@ -20,6 +22,7 @@
from trytond.transaction import Transaction
from trytond.exceptions import UserError
from trytond.model import ModelSQL, ModelView, Workflow, fields
from trytond import backend


__all__ = [
Expand Down Expand Up @@ -209,6 +212,11 @@ class PaymentTransaction(Workflow, ModelSQL, ModelView):
fields.Many2One('party.address', 'Shipping Address'),
'get_shipping_address'
)
credit_account = fields.Many2One(
'account.account', 'Credit Account',
states=READONLY_IF_NOT_DRAFT, depends=['state'],
required=True, select=True
)

def get_rec_name(self, name=None):
"""
Expand Down Expand Up @@ -304,6 +312,73 @@ def __setup__(cls):
}
})

cls.credit_account.domain = [
('company', '=', Eval('company', -1)),
('kind', 'in', cls._credit_account_domain())
]
cls.credit_account.depends += ['company']

@classmethod
def __register__(cls, module_name):
Party = Pool().get('party.party')
Model = Pool().get('ir.model')
ModelField = Pool().get('ir.model.field')
Property = Pool().get('ir.property')
TableHandler = backend.get('TableHandler')
cursor = Transaction().cursor
table = TableHandler(cursor, cls, module_name)

migration_needed = False
if not table.column_exist('credit_account'):
migration_needed = True

super(PaymentTransaction, cls).__register__(module_name)

if migration_needed and not Pool.test:
# Migration
# Set party's receivable account as the credit_account on
# transactions
transaction = cls.__table__()
party = Party.__table__()
property = Property.__table__()

account_model, = Model.search([
('model', '=', 'party.party'),
])
account_receivable_field, = ModelField.search([
('model', '=', account_model.id),
('name', '=', 'account_receivable'),
('ttype', '=', 'many2one'),
])

update = transaction.update(
columns=[transaction.credit_account],
values=[
Trim(
Substring(property.value, ',.*'), 'LEADING', ','
).cast(cls.credit_account.sql_type().base)
],
from_=[party, property],
where=(
transaction.party == party.id
) & (
property.res == Concat(Party.__name__ + ',', party.id)
) & (
property.field == account_receivable_field.id
) & (
property.company == transaction.company
)

)
cursor.execute(*update)

@classmethod
def _credit_account_domain(cls):
"""
Return a list of account kind
"""
return ['receivable']

@staticmethod
def default_uuid():
return unicode(uuid4())
Expand Down Expand Up @@ -350,8 +425,11 @@ def on_change_with_currency_digits(self, name=None):
def on_change_party(self):
res = {
'address': None,
'credit_account': None,
}
if self.party:
res['credit_account'] = self.party.account_receivable and \
self.party.account_receivable.id
try:
address = self.party.address_get(type='invoice')
except AttributeError:
Expand Down Expand Up @@ -594,7 +672,7 @@ def create_move(self, date=None):

lines = [{
'description': self.rec_name,
'account': self.party.account_receivable.id,
'account': self.credit_account.id,
'party': self.party.id,
'debit': Decimal('0.0'),
'credit': amount,
Expand Down
2 changes: 1 addition & 1 deletion tryton.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tryton]
version=3.4.2.1
version=3.4.3.0
depends:
party
account
Expand Down
3 changes: 3 additions & 0 deletions view/transaction_form.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ this repository contains the full copyright notices and license terms. -->
<field name="party"/>
<label name="address"/>
<field name="address"/>
<label name="credit_account"/>
<field name="credit_account"/>
<newline />
<label name="gateway"/>
<field name="gateway"/>
<label name="payment_profile"/>
Expand Down

0 comments on commit 8806aaa

Please sign in to comment.