Merge lp:~unifield-team/unifield-server/us-932 into lp:unifield-server

Proposed by jftempo
Status: Merged
Merged at revision: 3755
Proposed branch: lp:~unifield-team/unifield-server/us-932
Merge into: lp:unifield-server
Diff against target: 120 lines (+77/-3)
1 file modified
bin/addons/account_override/account.py (+77/-3)
To merge this branch: bzr merge lp:~unifield-team/unifield-server/us-932
Reviewer Review Type Date Requested Status
UniField Reviewer Team Pending
Review via email: mp+295154@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
=== modified file 'bin/addons/account_override/account.py'
--- bin/addons/account_override/account.py 2016-03-23 09:07:28 +0000
+++ bin/addons/account_override/account.py 2016-05-19 07:06:12 +0000
@@ -797,8 +797,59 @@
797 """797 """
798 Check that we can write on this if we come from web menu or synchronisation.798 Check that we can write on this if we come from web menu or synchronisation.
799 """799 """
800 if not context:800 def check_update_sequence(rec, new_journal_id, new_period_id):
801 """
802 returns new sequence move vals (sequence_id, name) or None
803 :rtype : dict/None
804 """
805 if m.state != 'draft':
806 return None
807
808 period_obj = self.pool.get('account.period')
809 period_rec = False
810 do_update = False
811
812 # journal or FY has changed ?
813 if new_journal_id and m.journal_id.id != new_journal_id:
814 do_update = True
815 if new_period_id and m.period_id.id != new_period_id:
816 period_rec = period_obj.browse(cr, uid, new_period_id)
817 do_update = period_rec.fiscalyear_id.id \
818 != m.period_id.fiscalyear_id.id # FY changed
819 if not do_update:
820 return None
821
822 # get instance and journal/period
823 instance_rec = self.pool.get('res.users').browse(cr, uid, uid,
824 context).company_id.instance_id
825 if not instance_rec.move_prefix:
826 raise osv.except_osv(_('Warning'),
827 _('No move prefix found for this instance!' \
828 ' Please configure it on Company view.'))
829 journal_rec = self.pool.get('account.journal').browse(cr, uid,
830 new_journal_id or m.journal_id.id)
831 period_rec = period_rec or m.period_id
832 if period_rec.state == 'created':
833 raise osv.except_osv(_('Error !'),
834 _("Period '%s' is not open!' \
835 ' No Journal Entry is updated") % (period_rec.name, ))
836
837 # get new sequence number and return related vals
838 sequence_number = self.pool.get('ir.sequence').get_id(
839 cr, uid, journal_rec.sequence_id.id,
840 context={ 'fiscalyear_id': period_rec.fiscalyear_id.id })
841 if instance_rec and journal_rec and sequence_number:
842 return {
843 'sequence_id': journal_rec.sequence_id.id,
844 'name': "%s-%s-%s" % (instance_rec.move_prefix,
845 journal_rec.code, sequence_number, ),
846 }
847 return None
848
849 if context is None:
801 context = {}850 context = {}
851 new_sequence_vals_by_move_id = {}
852
802 if context.get('from_web_menu', False) or context.get('sync_update_execution', False):853 if context.get('from_web_menu', False) or context.get('sync_update_execution', False):
803 # by default, from synchro, we just need to update period_id and journal_id854 # by default, from synchro, we just need to update period_id and journal_id
804 fields = ['journal_id', 'period_id']855 fields = ['journal_id', 'period_id']
@@ -811,6 +862,20 @@
811 raise osv.except_osv(_('Warning'), _('You cannot edit a Journal Entry created by the system.'))862 raise osv.except_osv(_('Warning'), _('You cannot edit a Journal Entry created by the system.'))
812 if m.journal_id.type == 'system':863 if m.journal_id.type == 'system':
813 raise osv.except_osv(_('Warning'), _('You can not edit a Journal Entry on a system journal'))864 raise osv.except_osv(_('Warning'), _('You can not edit a Journal Entry on a system journal'))
865
866 if context.get('from_web_menu', False) \
867 and not context.get('sync_update_execution', False):
868 # US-932: journal or FY changed ?
869 # typical UC: manual JE from UI: journal/period changed
870 # after a duplicate.
871 # check sequence and update it if needed. (we do not update
872 # it during on_change() to prevent sequence jumps)
873 new_seq = check_update_sequence(m,
874 vals.get('journal_id', False),
875 vals.get('period_id', False))
876 if new_seq:
877 new_sequence_vals_by_move_id[m.id] = new_seq
878
814 # Update context in order journal item could retrieve this @creation879 # Update context in order journal item could retrieve this @creation
815 # Also update some other fields880 # Also update some other fields
816 ml_vals = {}881 ml_vals = {}
@@ -818,15 +883,24 @@
818 if el in vals:883 if el in vals:
819 context[el] = vals.get(el)884 context[el] = vals.get(el)
820 ml_vals.update({el: vals.get(el)})885 ml_vals.update({el: vals.get(el)})
886
821 # UFTP-262: For manual_name (description on account.move), update "name" on account.move.line887 # UFTP-262: For manual_name (description on account.move), update "name" on account.move.line
822 if 'manual_name' in vals:888 if 'manual_name' in vals:
823 ml_vals.update({'name': vals.get('manual_name', '')})889 ml_vals.update({'name': vals.get('manual_name', '')})
890
824 # Update document date AND date at the same time891 # Update document date AND date at the same time
825 if ml_vals:892 if ml_vals:
826 ml_id_list = [ml.id for ml in m.line_id]893 ml_id_list = [ml.id for ml in m.line_id]
827 self.pool.get('account.move.line').write(cr, uid,894 self.pool.get('account.move.line').write(cr, uid,
828 ml_id_list, ml_vals, context, False, False)895 ml_id_list, ml_vals, context, False, False)
829 res = super(account_move, self).write(cr, uid, ids, vals, context=context)896
897 res = super(account_move, self).write(cr, uid, ids, vals,
898 context=context)
899 if new_sequence_vals_by_move_id:
900 for id in new_sequence_vals_by_move_id:
901 osv.osv.write(self, cr, uid, id,
902 new_sequence_vals_by_move_id[id], context=context) # US-932
903
830 self._check_document_date(cr, uid, ids, context)904 self._check_document_date(cr, uid, ids, context)
831 self._check_date_in_period(cr, uid, ids, context)905 self._check_date_in_period(cr, uid, ids, context)
832 return res906 return res
@@ -888,7 +962,7 @@
888 'state': 'draft',962 'state': 'draft',
889 'document_date': je.document_date,963 'document_date': je.document_date,
890 'date': je.date,964 'date': je.date,
891 'name': ''965 'name': '',
892 }966 }
893 res = super(account_move, self).copy(cr, uid, a_id, vals, context=context)967 res = super(account_move, self).copy(cr, uid, a_id, vals, context=context)
894 for line in je.line_id:968 for line in je.line_id:

Subscribers

People subscribed via source and target branches

to all changes: