[FIX] Pass the fiscal year in the context to use the right sequence if we have define...
authorStephane Wirtel <stephane@openerp.com>
Wed, 7 Jul 2010 16:06:12 +0000 (18:06 +0200)
committerStephane Wirtel <stephane@openerp.com>
Wed, 7 Jul 2010 16:06:12 +0000 (18:06 +0200)
[FIX] Redefine the form view for the sequence object with the fiscal years

bzr revid: stephane@openerp.com-20100707160612-8a7r1j0t81opz4w2

addons/account/invoice.py
addons/account/sequence.py
addons/account/sequence_view.xml

index 8af0a68..4cee8d6 100644 (file)
@@ -748,12 +748,18 @@ class account_invoice(osv.osv):
         obj_inv = self.browse(cr, uid, ids)[0]
         for (id, invtype, number, move_id, reference) in cr.fetchall():
             if not number:
+                tmp_context = {
+                    'fiscal_year_id' : obj_inv.period_id.fiscalyear_id.id,
+                    'test' : True,
+                }
                 if obj_inv.journal_id.invoice_sequence_id:
                     sid = obj_inv.journal_id.invoice_sequence_id.id
-                    number = self.pool.get('ir.sequence').get_id(cr, uid, sid, 'id=%s', {'fiscalyear_id': obj_inv.period_id.fiscalyear_id.id})
+                    number = self.pool.get('ir.sequence').get_id(cr, uid, sid, 'id=%s', context=tmp_context)
                 else:
-                    number = self.pool.get('ir.sequence').get(cr, uid,
-                            'account.invoice.' + invtype)
+                    number = self.pool.get('ir.sequence').get_id(cr, uid,
+                                                                 'account.invoice.' + invtype,
+                                                                 'code=%s',
+                                                                 context=tmp_context)
                 if invtype in ('in_invoice', 'in_refund'):
                     ref = reference
                 else:
index 8b38fe1..4f19dcc 100644 (file)
@@ -21,7 +21,7 @@
 ##############################################################################
 
 
-from osv import fields,osv
+from osv import fields, osv
 
 class ir_sequence_fiscalyear(osv.osv):
     _name = 'account.sequence.fiscalyear'
@@ -43,7 +43,11 @@ class ir_sequence(osv.osv):
     _columns = {
         'fiscal_ids' : fields.one2many('account.sequence.fiscalyear', 'sequence_main_id', 'Sequences')
     }
-    def get_id(self, cr, uid, sequence_id, test='id=%s', context={}):
+
+    def get_id(self, cr, uid, sequence_id, test='id=%s', context=None):
+
+        if context is None:
+            context = {}
         if test not in ('id=%s', 'code=%s'):
             raise ValueError('invalid test')
         cr.execute('select id from ir_sequence where '+test+' and active=%s', (sequence_id, True,))
index a2766af..673d3f9 100644 (file)
                                 <field name="fiscalyear_id"/>
                                 <field name="sequence_id"/>
                             </tree>
+                            <form string="Fiscal Year Sequence">
+                                <field name="fiscalyear_id"/>
+                                <field name="sequence_id"/>
+                            </form>
                         </field>
                     </page>
                 </page>