Merge lp:~julie-w/unifield-server/US-2897 into lp:unifield-server

Proposed by jftempo
Status: Merged
Merge reported by: jftempo
Merged at revision: not available
Proposed branch: lp:~julie-w/unifield-server/US-2897
Merge into: lp:unifield-server
Diff against target: 129 lines (+51/-30)
2 files modified
bin/addons/account_journal/account_journal.py (+33/-23)
bin/addons/account_journal/account_journal_view.xml (+18/-7)
To merge this branch: bzr merge lp:~julie-w/unifield-server/US-2897
Reviewer Review Type Date Requested Status
UniField Reviewer Team Pending
Review via email: mp+326744@code.launchpad.net
To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/addons/account_journal/account_journal.py'
2--- bin/addons/account_journal/account_journal.py 2017-05-26 10:03:57 +0000
3+++ bin/addons/account_journal/account_journal.py 2017-07-04 09:20:36 +0000
4@@ -216,6 +216,34 @@
5 self.pool.get('account.sequence.fiscalyear').create(cr, uid, {'sequence_id': sequence_id, 'fiscalyear_id': fiscalyear, 'sequence_main_id': main_sequence,})
6 return True
7
8+ def _create_linked_register(self, cr, uid, journal_id, vals, context):
9+ """
10+ If the journal is a liquidity journal creates the register linked to it if it doesn't exist yet
11+ """
12+ reg_obj = self.pool.get('account.bank.statement')
13+ # UTP-182: the register isn't created if the journal comes from another instance via the synchronization
14+ if 'type' in vals and vals['type'] in ('cash', 'bank', 'cheque') \
15+ and not context.get('sync_update_execution', False) and \
16+ not reg_obj.search_exist(cr, uid, [('journal_id', '=', journal_id)], context=context):
17+
18+ # 'from_journal_creation' in context permits to pass register creation that have a
19+ # 'prev_reg_id' mandatory field. This is because this register is the first register from this journal.
20+ context.update({'from_journal_creation': True})
21+
22+ #BKLG-53 get the next draft period from today
23+ current_date = datetime.date.today().strftime('%Y-%m-%d')
24+ periods = self.pool.get('account.period').search(cr, uid, [
25+ ('date_stop', '>=',current_date),
26+ ('state', '=', 'draft'),
27+ ('special', '=', False),
28+ ], context=context, limit=1, order='date_stop')
29+ if not periods:
30+ raise osv.except_osv(_('Warning'), _('Sorry, No open period for creating the register!'))
31+ reg_obj.create(cr, uid, {'journal_id': journal_id,
32+ 'name': vals['name'],
33+ 'period_id': periods[0],
34+ 'currency': vals.get('currency')}, context=context)
35+
36 def create(self, cr, uid, vals, context=None):
37 """
38 Create the journal with its sequence, a sequence linked to the fiscalyear and some register if this journal type is bank, cash or cheque.
39@@ -270,29 +298,8 @@
40 if vals['type'] in ['cash', 'bank', 'cheque', 'cur_adj']:
41 if not vals.get('default_debit_account_id'):
42 raise osv.except_osv(_('Warning'), _('Default Debit Account is missing.'))
43-
44- # if the journal can be linked to a register, the register is also created
45- # UTP-182: but not create if the journal came from another instance via the synchronization
46- if vals['type'] in ('cash','bank','cheque') and not context.get('sync_update_execution', False):
47- # 'from_journal_creation' in context permits to pass register creation that have a
48- # 'prev_reg_id' mandatory field. This is because this register is the first register from this journal.
49- context.update({'from_journal_creation': True})
50-
51- #BKLG-53 get the next draft period from today
52- current_date = datetime.date.today().strftime('%Y-%m-%d')
53- periods = self.pool.get('account.period').search(cr, uid, [
54- ('date_stop','>=',current_date),
55- ('state','=','draft'),
56- ('special', '=', False),
57- ], context=context, limit=1, order='date_stop')
58- if not periods:
59- raise osv.except_osv(_('Warning'), _('Sorry, No open period for creating the register!'))
60- self.pool.get('account.bank.statement') \
61- .create(cr, uid, {'journal_id': journal_id,
62- 'name': vals['name'],
63- 'period_id': periods[0],
64- 'currency': vals.get('currency')}, \
65- context=context)
66+ # if it is a liquidity journal create the linked register
67+ self._create_linked_register(cr, uid, journal_id, vals, context)
68
69 # Prevent user that default account for cur_adj type should be an expense account
70 if vals['type'] in ['cur_adj']:
71@@ -308,6 +315,8 @@
72 """
73 if not ids:
74 return True
75+ if isinstance(ids, (int, long)):
76+ ids = [ids]
77 if context is None:
78 context = {}
79
80@@ -322,6 +331,7 @@
81 for j in self.browse(cr, uid, ids):
82 if j.type == 'cur_adj' and j.default_debit_account_id.user_type_code != 'expense':
83 raise osv.except_osv(_('Warning'), _('Default Debit Account should be an expense account for Adjustement Journals!'))
84+ self._create_linked_register(cr, uid, j.id, vals, context)
85 # US-265: Check account bank statements if name change
86 if not context.get('sync_update_execution'):
87 if vals.get('name', False):
88
89=== modified file 'bin/addons/account_journal/account_journal_view.xml'
90--- bin/addons/account_journal/account_journal_view.xml 2016-11-04 12:57:37 +0000
91+++ bin/addons/account_journal/account_journal_view.xml 2017-07-04 09:20:36 +0000
92@@ -14,19 +14,30 @@
93 <group colspan="4" col="6">
94 <field name="has_entries" invisible="1"/>
95 <field name="name" select="1"/>
96- <field name="code" select="1" attrs="{'readonly': [('has_entries', '=', True)]}"/>
97- <field name="type" on_change="onchange_type(type, currency, context)"/>
98+ <field name="code" select="1"
99+ attrs="{'readonly': [('has_entries', '=', True)]}"/>
100+ <field name="type" on_change="onchange_type(type, currency, context)"
101+ attrs="{'readonly': [('has_entries', '=', True)]}"/>
102 </group>
103 <group col="2" colspan="2">
104 <separator string="Accounts" colspan="4"/>
105- <field name="default_debit_account_id" domain="[('type','&lt;&gt;','view'), ('cash_domain', '=', type)]" attrs="{'required': [('type', 'in', ('cash', 'bank', 'cheque', 'cur_adj'))]}"/>
106- <field name="default_credit_account_id" domain="[('type','&lt;&gt;','view'), ('cash_domain', '=', type)]" attrs="{'required': [('type', 'in', ('cash', 'bank', 'cheque', 'cur_adj'))]}"/>
107+ <field name="default_debit_account_id" domain="[('type','&lt;&gt;','view'), ('cash_domain', '=', type)]"
108+ attrs="{'required': [('type', 'in', ('cash', 'bank', 'cheque', 'cur_adj'))]}"/>
109+ <field name="default_credit_account_id" domain="[('type','&lt;&gt;','view'), ('cash_domain', '=', type)]"
110+ attrs="{'required': [('type', 'in', ('cash', 'bank', 'cheque', 'cur_adj'))]}"/>
111 </group>
112 <group colspan="2" col="2">
113 <separator string="Company" colspan="4"/>
114- <field name="currency" attrs="{'required': [('type', 'in', ('cash', 'bank', 'cheque'))]}"/>
115- <field name="analytic_journal_id" domain="[('is_current_instance','=',True)]" attrs="{'required': [('type', 'not in', ('situation', 'stock'))]}"/>
116- <field name="bank_journal_id" attrs="{'invisible': [('type', '!=', 'cheque')], 'required': [('type', '=', 'cheque')]}"/>
117+ <field name="currency"
118+ attrs="{'required': [('type', 'in', ('cash', 'bank', 'cheque'))],
119+ 'readonly': [('has_entries', '=', True)]}"/>
120+ <field name="analytic_journal_id" domain="[('is_current_instance','=',True)]"
121+ attrs="{'required': [('type', 'not in', ('situation', 'stock'))],
122+ 'readonly': [('has_entries', '=', True)]}"/>
123+ <field name="bank_journal_id"
124+ attrs="{'invisible': [('type', '!=', 'cheque')],
125+ 'required': [('type', '=', 'cheque')],
126+ 'readonly': [('has_entries', '=', True)]}"/>
127 </group>
128 <group colspan="4" col="4">
129 <label string="" colspan="2"/>

Subscribers

People subscribed via source and target branches