[MERGE] Contribution from Numerigraphe: lp:~numerigraphe/openobject-addons/bug602188-trunk
bzr revid: stephane@openerp.com-20100715141034-4f6be6xnxrvw3k8f
This commit is contained in:
@@ -127,6 +127,7 @@ module named account_vouchers
|
||||
'board_account_demo.xml',
|
||||
],
|
||||
'test': [
|
||||
'test/account_sequence_test.yml',
|
||||
'test/account_customer_invoice.yml',
|
||||
'test/account_supplier_invoice.yml',
|
||||
'test/account_change_currency.yml',
|
||||
|
||||
@@ -924,12 +924,20 @@ class account_invoice(osv.osv):
|
||||
move_id = obj_inv.move_id and obj_inv.move_id.id or False
|
||||
reference = obj_inv.reference
|
||||
if not number:
|
||||
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', {'fiscalyear_id': obj_inv.period_id.fiscalyear_id.id})
|
||||
tmp_context = {
|
||||
'fiscalyear_id': inv.period_id.fiscalyear_id.id
|
||||
}
|
||||
if inv.journal_id.invoice_sequence_id:
|
||||
sequence_id = inv.journal_id.invoice_sequence_id.id
|
||||
number = self.pool.get('ir.sequence').get_id(cr, uid,
|
||||
sequence_id,
|
||||
'id',
|
||||
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.%s' % invtype,
|
||||
'code',
|
||||
context=tmp_context)
|
||||
if invtype in ('in_invoice', 'in_refund'):
|
||||
ref = reference
|
||||
else:
|
||||
|
||||
+25
-13
@@ -19,19 +19,23 @@
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
from osv import fields,osv
|
||||
from osv import fields, osv
|
||||
|
||||
class ir_sequence_fiscalyear(osv.osv):
|
||||
_name = 'account.sequence.fiscalyear'
|
||||
_rec_name = "sequence_main_id"
|
||||
_columns = {
|
||||
"sequence_id": fields.many2one("ir.sequence", 'Sequence', required=True, ondelete='cascade'),
|
||||
"sequence_main_id": fields.many2one("ir.sequence", 'Main Sequence', required=True, ondelete='cascade'),
|
||||
"fiscalyear_id": fields.many2one('account.fiscalyear', 'Fiscal Year', required=True, ondelete='cascade')
|
||||
"sequence_id": fields.many2one("ir.sequence", 'Sequence', required=True,
|
||||
ondelete='cascade'),
|
||||
"sequence_main_id": fields.many2one("ir.sequence", 'Main Sequence',
|
||||
required=True, ondelete='cascade'),
|
||||
"fiscalyear_id": fields.many2one('account.fiscalyear', 'Fiscal Year',
|
||||
required=True, ondelete='cascade')
|
||||
}
|
||||
|
||||
_sql_constraints = [
|
||||
('main_id', 'CHECK (sequence_main_id != sequence_id)', 'Main Sequence must be different from current !'),
|
||||
('main_id', 'CHECK (sequence_main_id != sequence_id)',
|
||||
'Main Sequence must be different from current !'),
|
||||
]
|
||||
|
||||
ir_sequence_fiscalyear()
|
||||
@@ -39,17 +43,25 @@ ir_sequence_fiscalyear()
|
||||
class ir_sequence(osv.osv):
|
||||
_inherit = 'ir.sequence'
|
||||
_columns = {
|
||||
'fiscal_ids' : fields.one2many('account.sequence.fiscalyear', 'sequence_main_id', 'Sequences')
|
||||
'fiscal_ids' : fields.one2many('account.sequence.fiscalyear',
|
||||
'sequence_main_id', 'Sequences')
|
||||
}
|
||||
def get_id(self, cr, uid, sequence_id, test='id', context={}):
|
||||
cr.execute('select id from ir_sequence where '+test+'=%s and active=%s', (sequence_id, True,))
|
||||
def get_id(self, cr, uid, sequence_id, test='id', context=None):
|
||||
if context is None:
|
||||
context = {}
|
||||
cr.execute('select id from ir_sequence where '
|
||||
+ test + '=%s and active=%s', (sequence_id, True,))
|
||||
res = cr.dictfetchone()
|
||||
if res:
|
||||
for line in self.browse(cr, uid, res['id'], context=context).fiscal_ids:
|
||||
if line.fiscalyear_id.id==context.get('fiscalyear_id', False):
|
||||
return super(ir_sequence, self).get_id(cr, uid, line.sequence_id.id, test="id", context=context)
|
||||
return super(ir_sequence, self).get_id(cr, uid, sequence_id, test, context)
|
||||
for line in self.browse(cr, uid, res['id'],
|
||||
context=context).fiscal_ids:
|
||||
if line.fiscalyear_id.id == context.get('fiscalyear_id', False):
|
||||
return super(ir_sequence, self).get_id(cr, uid,
|
||||
line.sequence_id.id,
|
||||
test="id",
|
||||
context=context)
|
||||
return super(ir_sequence, self).get_id(cr, uid, sequence_id, test,
|
||||
context=context)
|
||||
ir_sequence()
|
||||
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
@@ -14,6 +14,10 @@
|
||||
<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>
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
- In order to test the invoice numbering, I create a sequence for out invoices.
|
||||
- !record {model: ir.sequence, id: seq_out_invoice_test}:
|
||||
name: Account Invoice Out for the demonstration Fiscal Year # XXX indicate the name of the fiscal year
|
||||
code: account.invoice.out_invoice
|
||||
padding: 3
|
||||
prefix: FY-
|
||||
suffix: -TEST
|
||||
number_next: 42
|
||||
|
||||
- I link the new sequence to the demo sequence and the demo fiscal years.
|
||||
- !record {model: account.sequence.fiscalyear, id: seq_out_invoice_test_fy}:
|
||||
sequence_id: seq_out_invoice_test
|
||||
sequence_main_id: seq_out_invoice
|
||||
fiscalyear_id: data_fiscalyear
|
||||
|
||||
- I create a draft customer invoice in a period of the demo fiscal year
|
||||
- !record {model: account.invoice, id: invoice_seq_test}:
|
||||
account_id: account.a_recv
|
||||
address_contact_id: base.res_partner_address_zen
|
||||
address_invoice_id: base.res_partner_address_zen
|
||||
company_id: base.main_company
|
||||
currency_id: base.EUR
|
||||
invoice_line:
|
||||
- account_id: account.a_sale
|
||||
name: '[PC3] Medium PC'
|
||||
price_unit: 900.0
|
||||
quantity: 10.0
|
||||
product_id: product.product_product_pc3
|
||||
uos_id: product.product_uom_unit
|
||||
journal_id: account.sales_journal
|
||||
partner_id: base.res_partner_3
|
||||
reference_type: none
|
||||
period_id: period_1
|
||||
|
||||
- I create the invoice, as is I clicked on the "Create" button
|
||||
- !workflow {model: account.invoice, action: invoice_open, ref: invoice_seq_test}
|
||||
|
||||
- I check that the invoice state is "Open"
|
||||
- !assert {model: account.invoice, id: invoice_seq_test}:
|
||||
- state == 'open'
|
||||
|
||||
- I check that the invoice got the right number using our sequence
|
||||
# This used to fail because of bug #602188
|
||||
- !assert {model: account.invoice, id: invoice_seq_test}:
|
||||
- number == 'FY-042-TEST'
|
||||
Reference in New Issue
Block a user