跳至内容
菜单
此问题已终结
2 回复
9032 查看

We create new Journal Entries from 

1. Accounting > Accounting Entries > Journal Entries > Create
2. On save Journal Entry Number (name field) is created as /
3. On Journal Entry posting system generates its sequence number like GJ/2019/0004

How we can generate Journal Entry Number on Save? Odoo 12

形象
丢弃
编写者 最佳答案

Here is, how I done it by overriding Create method,

class SCTAccountMove(models.Model):
_inherit = 'account.move'
@api.model
def create(self, values):
result = super(SCTAccountMove, self).create(values)
journal = values.get('journal_id') and self.env['account.journal'].browse(values.get('journal_id'))
if journal.sequence_id:
sequence = journal.sequence_id
result['name'] = sequence.with_context(ir_sequence_date=values.get('date')).next_by_id()
else:
raise UserError(_('Please define a sequence on the journal.'))
return result
形象
丢弃

Allthough this may work, it is not a solution. Either it is an Odoo bug and should be properly reported, or Lars' suggestion should be applied.

编写者

Hii twanda AG. Its default in odoo 12. On save journal entry number is not generated. It is generated in post method. But our customer need to generate it on Save method, so I tried to do it like this.

Ah, now I see, sorry for the misunderstanding and forget my comment.

编写者

No problem. I am happy you commented.

What does happen then with the sequence, when you post the entry later?

编写者

Good question.

In the post method there is if move.name == '/': but now in my case its not '/' its like 'GJ/2019/0004' so system will not generate any sequence.

So far working fine with us on posting.

最佳答案

Looks like something gone wrong woth the number sequence.

Activate developer tools.  Go to Accounting->Configuration->Journals. Open the journal you need to modify.

You find a field named Next Number. There you should see a link to the sequence related to the journal. Click on it and you can modify the sequence.

A sequence should be generated automatic when a journal is created.


形象
丢弃
编写者

Hii Lars. In Odoo 12 when we create a journal entry and save it, system do not generate next number sequence instead it assigns '/' to the name field. When Posting the entry at that time system generates number sequence. In the save method they are not calling number sequence, they are calling it in the post method.

What I did is to generate sequence in Save method to fulfill our requirements.

相关帖文 回复 查看 活动
1
3月 15
3353
2
7月 25
1420
0
1月 24
1409
1
11月 23
1675
1
9月 23
2341