diff --git a/CHANGELOG b/CHANGELOG
index b848298492..1fc9ac6988 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,5 @@
+* Add origin field on payment
+
Version 4.4.0 - 2017-05-01
* Bug fixes (see mercurial logs for details)
* Support direct debit of payable line
diff --git a/payment.py b/payment.py
index 674529f5dc..f95ddbd887 100644
--- a/payment.py
+++ b/payment.py
@@ -119,7 +119,8 @@ class Payment(Workflow, ModelSQL, ModelView):
],
depends=_DEPENDS + ['company'])
currency = fields.Function(fields.Many2One('currency.currency',
- 'Currency'), 'on_change_with_currency')
+ 'Currency'), 'on_change_with_currency',
+ searcher='search_currency')
currency_digits = fields.Function(fields.Integer('Currency Digits'),
'on_change_with_currency_digits')
kind = fields.Selection(KINDS, 'Kind', required=True,
@@ -156,6 +157,12 @@ class Payment(Workflow, ModelSQL, ModelView):
states=_STATES, depends=_DEPENDS + ['party', 'currency', 'kind',
'company'])
description = fields.Char('Description', states=_STATES, depends=_DEPENDS)
+ origin = fields.Reference(
+ "Origin", selection='get_origin', select=True,
+ states={
+ 'readonly': Eval('state') != 'draft',
+ },
+ depends=['state'])
group = fields.Many2One('account.payment.group', 'Group', readonly=True,
ondelete='RESTRICT',
states={
@@ -240,6 +247,10 @@ class Payment(Workflow, ModelSQL, ModelView):
return self.journal.currency.digits
return 2
+ @classmethod
+ def search_currency(cls, name, clause):
+ return [('journal.currency',) + tuple(clause[1:])]
+
@fields.depends('kind')
def on_change_kind(self):
self.line = None
@@ -254,6 +265,20 @@ class Payment(Workflow, ModelSQL, ModelView):
self.date = self.line.maturity_date
self.amount = self.line.payment_amount
+ @classmethod
+ def _get_origin(cls):
+ 'Return list of Model names for origin Reference'
+ return []
+
+ @classmethod
+ def get_origin(cls):
+ Model = Pool().get('ir.model')
+ models = cls._get_origin()
+ models = Model.search([
+ ('model', 'in', models),
+ ])
+ return [(None, '')] + [(m.model, m.name) for m in models]
+
@classmethod
def delete(cls, payments):
for payment in payments:
diff --git a/view/payment_form.xml b/view/payment_form.xml
index 1f351a8ba9..e8d256edab 100644
--- a/view/payment_form.xml
+++ b/view/payment_form.xml
@@ -26,6 +26,8 @@ this repository contains the full copyright notices and license terms. -->
+
+