跳至内容
菜单
此问题已终结

Is it possible to automatically create credit notes when confirming returns of goods using automated actions?

形象
丢弃
最佳答案

Hello Ricardo Gross

Yes, it is possible to create credit notes while returning goods.

when we returns product, system create stock.picking record with value of Reference = "Return of WH/OUT/00016". so we can create automatic action on create new record of stock.picking model to check reference value if it is start with "Return" keyword then get sale_id (default field in stock.picking)

Now sale order do have invoice_ids fiels to get invoice and we can call "reverse_move" of those invoice to crate credit notes.

please check automated action with python code 


# check if action trigger for return order and related sale order has invoice created with payment
if
record.origin.startswith('Return of') and record.sale_id.invoice_ids.filtered(lambda move: move.state == 'posted'):
invoice_ids = record.sale_id.invoice_ids.filtered(lambda move: move.state == 'posted')
# create refund wizard
move_reversal = env['account.move.reversal'].with_context(active_model="account.move", active_ids=invoice_ids.ids).create({
'date': datetime.datetime.today().strftime('%Y-%m-%d'),
'reason': 'no reason',
'refund_method': 'refund',
'journal_id': invoice_ids.journal_id.id,})
# create revese move
move_reversal.reverse_moves()
# get last invoice as credit note
invoice_refund = record.sale_id.invoice_ids.sorted(key=lambda inv: inv.id, reverse=False)[-1]
# post credit note invoice_refund.action_post()

Result:



Thanks & Regards,



CandidRoot Solutions Pvt. Ltd.

Mobile: (+91) 8849036209
Email: info@candidroot.com
Skype: live:candidroot
Web: https://www.candidroot.com
Address: 1229-1230, Iconic Shyamal, Near Shyamal Cross Road, Ahmedabad, Gujarat 380015
     

形象
丢弃
编写者

Thank you CandidRoot for your answer and the information provided, but trying to create the automated action, I must be making some mistake, could you please explain how to setup this, I am sure that other followers of this forum would also appreciate

Hello Ricardo Gross,
Based on your request i have provied automation action with python code.

please check my updated answer and mark as best answer if it is helpfull

Thank you very much for detailed solution

编写者

Thank you very much! there is still a small detail to correct, because in this way, the credit note is already being created before I confirm the return, and if I delivery 2 units and return only 1, the credit note should be only for 1, not 2 units

最佳答案

I usually solve the problem of automatically generating credit notes after a confirmed return using Automated Actions combined with a small Python script. The key is to make sure that the credit note is only generated after a confirmed return and only for orders that have been invoiced. If you have time, check out https://unblockedgamespremium.io for more details.

形象
丢弃
最佳答案

Gracias amigo, me funcionó para V17 pero tuve que eliminar #'refund_method': 'refund' ya que ese campo no está disponible en el modelo account.move.reversal

形象
丢弃
相关帖文 回复 查看 活动
1
12月 24
6362
1
8月 24
1813
2
2月 23
4809
2
7月 18
4723
3
10月 24
2785