diff --git a/__manifest__.py b/__manifest__.py index 7157fe7..22f4552 100644 --- a/__manifest__.py +++ b/__manifest__.py @@ -41,6 +41,8 @@ #'views/mail_mail.xml', 'views/returnmail.xml', 'views/payment_batch.xml', + 'views/bank_deposit.xml', + 'views/accounting_deposit.xml', 'views/website_sale.xml', 'views/aggregate.xml', 'views/duplicate.xml', @@ -48,10 +50,13 @@ 'views/template_pa.xml', 'wizard/operation_duplicate_wizard.xml', 'wizard/recurring_donation_wizard.xml', + 'wizard/create_bank_deposit_wizard.xml', + 'wizard/create_accounting_deposit_wizard.xml', 'report/report_donationtax.xml', 'report/report_donation_recurring.xml', 'report/report.xml', 'report/report_donationthanks.xml', + #'report/report_bank_deposit.xml', 'views/donation_tax_receipt.xml', 'views/donation_thanks_template.xml', 'views/laposte_ref.xml', diff --git a/models/__init__.py b/models/__init__.py index dc9229c..5196a65 100644 --- a/models/__init__.py +++ b/models/__init__.py @@ -25,4 +25,6 @@ from . import donation_recurring_template_letter from . import donation_thanks_template from . import partner_import #from . import res_partner_bank -from .import donation_print_email_history \ No newline at end of file +from .import donation_print_email_history +from .import bank_deposit +from .import accounting_deposit \ No newline at end of file diff --git a/models/accounting_deposit.py b/models/accounting_deposit.py new file mode 100644 index 0000000..ed32131 --- /dev/null +++ b/models/accounting_deposit.py @@ -0,0 +1,24 @@ +from odoo import models, fields, api +from odoo.exceptions import UserError, ValidationError,Warning +from psycopg2 import sql, DatabaseError + +from werkzeug import utils + +class opendons_accounting_deposit(models.Model): + _name = 'opendons.accountingdeposit' + _description = 'manage accounting deposit' + + + company_id = fields.Many2one( + "res.company", + string="Company", + ondelete="cascade", + default=lambda self: self.env.company, + ) + payment_batch_ids = fields.One2many( + 'opendons_payment_batch', + 'accountingdeposit_id', + string='Payment batchs', + readonly=True + ) + \ No newline at end of file diff --git a/models/bank_deposit.py b/models/bank_deposit.py new file mode 100644 index 0000000..19d8c58 --- /dev/null +++ b/models/bank_deposit.py @@ -0,0 +1,24 @@ +from odoo import models, fields, api +from odoo.exceptions import UserError, ValidationError,Warning +from psycopg2 import sql, DatabaseError + +from werkzeug import utils + +class opendons_bank_deposit(models.Model): + _name = 'opendons.bankdeposit' + _description = 'manage bank deposit' + + + company_id = fields.Many2one( + "res.company", + string="Company", + ondelete="cascade", + default=lambda self: self.env.company, + ) + payment_batch_ids = fields.One2many( + 'opendons_payment_batch', + 'bankdeposit_id', + string='Payment batchs', + readonly=True + ) + \ No newline at end of file diff --git a/models/donation.py b/models/donation.py index 46721b5..a208440 100644 --- a/models/donation.py +++ b/models/donation.py @@ -122,17 +122,36 @@ class DonationDonation(models.Model): states={"done": [("readonly", True)]} ) + bank_deposit_date=fields.Date('bank deposit date') + accounting_deposit_date=fields.Date('bank deposit date') @api.model def create(self, vals): vals['tax_receipt_option']='annual' res = super(DonationDonation, self).create(vals) - + + #si don hors lot de paiement, création auto du lot de paiement + if not res.payment_batch_id and res.state!='draft' : + vals={} + vals['payment_mode_id']=int(res.payment_mode_id) + batch=self.env['opendons_payment_batch'].create(vals) + batch.write({'donation_ids':[(4,int(res.id))]}) return res + + def write(self, vals): + + res = super(DonationDonation, self).write(vals) + #si don hors lot de paiement, création auto du lot de paiement + if not self.payment_batch_id and self.state!='draft' : + vals={} + vals['payment_mode_id']=int(self.payment_mode_id) + batch=self.env['opendons_payment_batch'].create(vals) + batch.write({'donation_ids':[(4,int(self.id))]}) + @api.onchange("partner_id") diff --git a/models/payment_batch.py b/models/payment_batch.py index 6b25dd9..e130708 100644 --- a/models/payment_batch.py +++ b/models/payment_batch.py @@ -66,7 +66,52 @@ class opendons_payment_batch(models.Model): string='donation', track_visibility='onchange') + deposited_in_bank=fields.Boolean('deposited in bank') + bank_deposit_date=fields.Datetime(related='bankdeposit_id.create_date') + accounting_deposit_date=fields.Datetime(related='accountingdeposit_id.create_date') + bankdeposit_id = fields.Many2one( + 'opendons.bankdeposit', + String='Bank deposit', + index=True, + readonly=True, + track_visibility='onchange', + + ) + accountingdeposit_id = fields.Many2one( + 'opendons.accountingdeposit', + String='Accounting deposit', + index=True, + readonly=True, + track_visibility='onchange', + + ) + state = fields.Selection([ + ('draft', 'Draft'), + ('validated', 'Validated'), + ('deposited_in_bank', 'Deposited in bank'), + ('deposited_in_accounting', 'Deposited in accounting') + ], + string='State', + readonly=True, + copy=False, + default='draft', + index=True, + track_visibility='onchange' + ) + + + def validate(self): + for payment in self: + vals = {'state': 'validated'} + payment.write(vals) + + return + def validated2draft(self): + '''from Done state to Cancel state''' + for payment in self: + + payment.state = 'draft' @api.model def _default_currency(self): diff --git a/report/report.xml b/report/report.xml index 8ce785f..a40ec87 100644 --- a/report/report.xml +++ b/report/report.xml @@ -43,4 +43,17 @@ report + + \ No newline at end of file diff --git a/report/report_bank_deposit.xml b/report/report_bank_deposit.xml new file mode 100644 index 0000000..e69de29 diff --git a/security/ir.model.access.csv b/security/ir.model.access.csv index 2453ccf..639c21b 100644 --- a/security/ir.model.access.csv +++ b/security/ir.model.access.csv @@ -50,4 +50,10 @@ access_opendons_print_donation_email_history,opendons_print_donation_email_histo access_opendons_partnerdraft,opendons_partnerdraft,model_opendons_partnerdraft,donation.group_donation_manager,1,1,1,1 access_opendons_partnerdraftfile,opendons_partnerdraftfile,model_opendons_partnerdraftfile,donation.group_donation_manager,1,1,1,1 -access_opendons_partnerdraft_file_mapping,opendons_partnerdraft_file_mapping,model_opendons_partnerdraftfile_mapping,donation.group_donation_manager,1,1,1,1 \ No newline at end of file +access_opendons_partnerdraft_file_mapping,opendons_partnerdraft_file_mapping,model_opendons_partnerdraftfile_mapping,donation.group_donation_manager,1,1,1,1 + +access_opendons_create_bank_deposit_wizard,opendons_create_bank_deposit_wizard,model_opendons_createbankdeposit,donation.group_donation_manager,1,1,1,1 +access_opendons_create_accounting_deposit_wizard,opendons_create_accounting_deposit_wizard,model_opendons_createaccountingdeposit,donation.group_donation_manager,1,1,1,1 + +access_opendons_bank_deposit,opendons_bank_deposit,model_opendons_bankdeposit,donation.group_donation_manager,1,1,1,1 +access_opendons_accounting_deposit,opendons_accounting_deposit,model_opendons_accountingdeposit,donation.group_donation_manager,1,1,1,1 \ No newline at end of file diff --git a/views/accounting_deposit.xml b/views/accounting_deposit.xml new file mode 100644 index 0000000..5d0f473 --- /dev/null +++ b/views/accounting_deposit.xml @@ -0,0 +1,59 @@ + + + + + + + opendons_accounting_deposit list + opendons.accountingdeposit + + + + + + + + + + + + opendons_payment_batch_accounting Form + opendons.accountingdeposit + + + + + + + + + + + + + + + + + + + + + + + + + + accounting deposits + opendons.accountingdeposit + tree,form + + + + + + + + + \ No newline at end of file diff --git a/views/bank_deposit.xml b/views/bank_deposit.xml new file mode 100644 index 0000000..6c7fbc6 --- /dev/null +++ b/views/bank_deposit.xml @@ -0,0 +1,61 @@ + + + + + + + opendons_bank_deposit list + opendons.bankdeposit + + + + + + + + + + + + opendons_payment_batch_bank Form + opendons.bankdeposit + + + + + + + + + + + + + + + + + + + + + + + + + + + + Bank deposits + opendons.bankdeposit + tree,form + + + + + + + + + \ No newline at end of file diff --git a/views/payment_batch.xml b/views/payment_batch.xml index 355ca12..dfd89b4 100644 --- a/views/payment_batch.xml +++ b/views/payment_batch.xml @@ -1,22 +1,18 @@ - + opendons_payment_batch list opendons_payment_batch + + + @@ -30,6 +26,14 @@ + + + + @@ -90,8 +94,24 @@ Payment batch opendons_payment_batch tree,form + {"search_default_not_deposited_in_bank":1} + + + + opendons_payment_batch.search + opendons_payment_batch + + + + + + + + + + + + \ No newline at end of file diff --git a/wizard/__init__.py b/wizard/__init__.py index 0899386..328340f 100644 --- a/wizard/__init__.py +++ b/wizard/__init__.py @@ -1,2 +1,4 @@ from . import operation_duplicate_wizard -from . import recurring_donation_wizard \ No newline at end of file +from . import recurring_donation_wizard +from . import create_bank_deposit_wizard +from . import create_accounting_deposit_wizard \ No newline at end of file diff --git a/wizard/create_accounting_deposit_wizard.py b/wizard/create_accounting_deposit_wizard.py new file mode 100644 index 0000000..b961cc7 --- /dev/null +++ b/wizard/create_accounting_deposit_wizard.py @@ -0,0 +1,29 @@ +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' + + + diff --git a/wizard/create_accounting_deposit_wizard.xml b/wizard/create_accounting_deposit_wizard.xml new file mode 100644 index 0000000..2c3a09c --- /dev/null +++ b/wizard/create_accounting_deposit_wizard.xml @@ -0,0 +1,29 @@ + + + + create_accounting_deposit view + opendons.createaccountingdeposit + + + + Are you sure do you want to create a accounting deposit with selected payments ? + + + + + + + + + + Create an accounting deposit + opendons.createaccountingdeposit + form + new + + + + \ No newline at end of file diff --git a/wizard/create_bank_deposit_wizard.py b/wizard/create_bank_deposit_wizard.py new file mode 100644 index 0000000..7cc59ee --- /dev/null +++ b/wizard/create_bank_deposit_wizard.py @@ -0,0 +1,38 @@ +from odoo import fields, models, _ +from odoo.exceptions import UserError, ValidationError,Warning + +class CreateBankDeposit(models.TransientModel): + _name = 'opendons.createbankdeposit' + _description = 'Create a bank deposit form batchs selected' + + + def create_bank_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.state=='draft': raise Warning('the batch payment selected is not validated : operation cancelled') + if p.accounting_deposit_date: raise Warning('the batch payment selected was already deposited in accounting : operation cancelled') + if p.bank_deposit_date: raise Warning('the batch payment selected was already deposited in bank : operation cancelled') + #create bank deposit + vals={} + bd=self.env['opendons.bankdeposit'].create(vals) + + for p in self.env['opendons_payment_batch'].browse(active_ids): + + #add payment to bank deposit + bd.write({'payment_batch_ids':[(4,p.id)]}) + + #add bank deposit to payment + p.bankdeposit_id=bd.id + p.state='deposited_in_bank' + + + # #creation de l'opération sans les segments + # vals={} + # vals['name']='copy of ' + record.name + # vals['chanel']=record.chanel + # vals['user_id']=self._uid + # vals['state']='draft' + # dup_operation=super(opendons_operation, self).create(vals) diff --git a/wizard/create_bank_deposit_wizard.xml b/wizard/create_bank_deposit_wizard.xml new file mode 100644 index 0000000..6d74aed --- /dev/null +++ b/wizard/create_bank_deposit_wizard.xml @@ -0,0 +1,29 @@ + + + + create_bank_deposit view + opendons.createbankdeposit + + + + Are you sure do you want to create a bank deposit with selected payments ? + + + + + + + + + + Create a bank deposit + opendons.createbankdeposit + form + new + + + + \ No newline at end of file
+ Are you sure do you want to create a accounting deposit with selected payments ? +
+ Are you sure do you want to create a bank deposit with selected payments ? +