|
from odoo import fields, models, _
|
|
from odoo.exceptions import UserError, ValidationError,Warning
|
|
|
|
class CreateaccountingDeposit(models.TransientModel):
|
|
_name = 'opendons.createaccountingdeposit'
|
|
_description = 'Create a accounting deposit form batchs selected'
|
|
|
|
def create_accounting_deposit(self):
|
|
active_ids = self._context.get('active_ids', []) or []
|
|
if active_ids:
|
|
payments=self.env['opendons_payment_batch'].browse(active_ids)
|
|
for p in payments:
|
|
if p.bank_deposit_date==False: raise Warning('the batch payment selected was not deposited in bank : operation cancelled')
|
|
if p.accounting_deposit_date: raise Warning('the batch payment selected was already deposited in bank : operation cancelled')
|
|
#create accounting deposit
|
|
vals={}
|
|
bd=self.env['opendons.accountingdeposit'].create(vals)
|
|
|
|
for p in payments:
|
|
|
|
#add payment to accounting deposit
|
|
bd.write({'payment_batch_ids':[(4,p.id)]})
|
|
|
|
#add accounting deposit to payment
|
|
p.accountingdeposit_id=bd.id
|
|
p.state='deposited_in_accounting'
|
|
|
|
|
|
|