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,
|
|
)
|
|
manual_mode_payment_id=fields.Many2one(
|
|
"account.payment.mode",
|
|
string="manual mode payment",
|
|
compute="_compute_manual_mode_payment"
|
|
)
|
|
|
|
payment_batch_ids = fields.One2many(
|
|
'opendons_payment_batch',
|
|
'bankdeposit_id',
|
|
string='Payment batchs',
|
|
readonly=True
|
|
)
|
|
@api.model
|
|
def _default_currency(self):
|
|
company = self.env['res.company']._company_default_get(
|
|
'donation.donation')
|
|
return company.currency_id
|
|
|
|
currency_id = fields.Many2one(
|
|
'res.currency',
|
|
string='Currency',
|
|
required=True,
|
|
states={'done': [('readonly', True)]},
|
|
track_visibility='onchange',
|
|
ondelete='restrict',
|
|
default=_default_currency
|
|
)
|
|
donation_count=fields.Integer('donation count',compute='_compute_donation_count')
|
|
total_amount=fields.Integer('total amount',compute='_compute_total_amount')
|
|
# template_bankdeposit_id=fields.Many2one('opendons.template_bankdeposit', 'bank deposit template')
|
|
# html_content=fields.Html('html content',compute='_html_content_rf')
|
|
# html_content_print=fields.Html('html content print')
|
|
def _compute_donation_count(self):
|
|
i=0
|
|
for p in self.payment_batch_ids:
|
|
for d in p.donation_ids:
|
|
for ld in d.line_ids:
|
|
i=i+1
|
|
self.donation_count=i-1
|
|
|
|
def _compute_total_amount(self):
|
|
i=0
|
|
for p in self.payment_batch_ids:
|
|
for d in p.donation_ids:
|
|
for ld in d.line_ids:
|
|
i=i+ld.amount
|
|
self.total_amount=i
|
|
|
|
def _compute_manual_mode_payment(self):
|
|
manual_method_payment=self.env['account.payment.method'].search([('code','=','manual')],limit=1)
|
|
if manual_method_payment:
|
|
m=self.env['account.payment.mode'].search([('payment_method_id','=',int(manual_method_payment.id))],limit=1)
|
|
if m:
|
|
self.manual_mode_payment_id=m.id
|
|
def action_print_bankdeposit(self):
|
|
self.ensure_one()
|
|
|
|
return self.env.ref("opendons.report_bankdeposits").report_action(self)
|
|
|
|
class opendons_bank_deposit_template(models.Model):
|
|
_name = 'opendons.bankdeposit.template'
|
|
_description = 'manage bank deposit template'
|
|
|
|
|
|
name=fields.Char('name')
|
|
description=fields.Text('description')
|
|
active=fields.Boolean('active')
|
|
html_page_header=fields.Html('Html page header')
|
|
html_page_section=fields.Html('Html page section')
|
|
html_page_footer=fields.Html('Html page footer')
|
|
|
|
|