accounting bank and cash
parent
c93b6dbe48
commit
aec988c6cc
|
@ -1 +1,2 @@
|
||||||
from . import ledger_bank_and_cash
|
from . import ledger_bank_and_cash
|
||||||
|
from . import snk_bank_and_cash
|
|
@ -5,6 +5,7 @@ class LedgerBankAndCash(models.Model):
|
||||||
_name = 'ledger.bank.and.cash'
|
_name = 'ledger.bank.and.cash'
|
||||||
_description = 'Bank and Cash Report'
|
_description = 'Bank and Cash Report'
|
||||||
_order = 'account_id, date asc'
|
_order = 'account_id, date asc'
|
||||||
|
_auto = False
|
||||||
|
|
||||||
date = fields.Date()
|
date = fields.Date()
|
||||||
account_id = fields.Many2one('account.account')
|
account_id = fields.Many2one('account.account')
|
||||||
|
@ -19,5 +20,7 @@ class LedgerBankAndCash(models.Model):
|
||||||
account_code = fields.Char('Account Code', related='account_id.code')
|
account_code = fields.Char('Account Code', related='account_id.code')
|
||||||
account_name = fields.Char('Account Name', related='account_id.name')
|
account_name = fields.Char('Account Name', related='account_id.name')
|
||||||
balance = fields.Monetary('Balance',)
|
balance = fields.Monetary('Balance',)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
from odoo import models, fields, api, _
|
||||||
|
|
||||||
|
|
||||||
|
class SnkBankAndCashReport(models.Model):
|
||||||
|
_name = 'snk.bank.and.cash.report'
|
||||||
|
_description = 'Bank and Cash Report'
|
||||||
|
_order = 'id asc'
|
||||||
|
_auto = False
|
||||||
|
|
||||||
|
|
||||||
|
date = fields.Date()
|
||||||
|
account_id = fields.Many2one('account.account')
|
||||||
|
description = fields.Char()
|
||||||
|
partner_id = fields.Many2one('res.partner')
|
||||||
|
currency_id = fields.Many2one('res.currency')
|
||||||
|
debit = fields.Monetary('Debit')
|
||||||
|
credit = fields.Monetary('Credit')
|
||||||
|
balance = fields.Monetary('Balance',)
|
|
@ -1,3 +1,4 @@
|
||||||
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
|
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
|
||||||
access_lsbl_ledger_bank_and_cash,lsbl_ledger_bank_and_cash,model_ledger_bank_and_cash,base.group_user,1,1,1,1
|
access_lsbl_ledger_bank_and_cash,lsbl_ledger_bank_and_cash,model_ledger_bank_and_cash,base.group_user,1,1,1,1
|
||||||
access_wz_ledger_bank_and_cash,wz_ledger_bank_and_cash,model_wz_ledger_bank_and_cash,base.group_user,1,1,1,1
|
access_wz_ledger_bank_and_cash,wz_ledger_bank_and_cash,model_wz_ledger_bank_and_cash,base.group_user,1,1,1,1
|
||||||
|
snk_bank_and_cash_report_access,snk_bank_and_cash_report_access,model_snk_bank_and_cash_report,account.group_account_invoice,1,1,1,1
|
|
|
@ -1,30 +1,26 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<odoo>
|
<odoo>
|
||||||
|
|
||||||
<record id="accounting_report_ledger_bank_and_cash_view_tree" model="ir.ui.view">
|
<record id="snk_accounting_report_ledger_bank_and_cash_view_tree" model="ir.ui.view">
|
||||||
<field name="name">accounting.report.ledger.bank.and.cash.view.tree</field>
|
<field name="name">snk.accounting.report.ledger.bank.and.cash.view.tree</field>
|
||||||
<field name="model">ledger.bank.and.cash</field>
|
<field name="model">snk.bank.and.cash.report</field>
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<tree create="false" delete="false" edit="false">
|
<tree create="false" delete="false" edit="false">
|
||||||
<field name="date"/>
|
<field name="date"/>
|
||||||
<field name="account_id" invisible='1'/>
|
<field name="account_id"/>
|
||||||
<field name="account_code" string="Account No"/>
|
<field name="description" string="Description"/>
|
||||||
<field name="account_name" string="Account Name"/>
|
|
||||||
<field name="move_id" string="Nomor Dokumen"/>
|
|
||||||
<field name="name" string="Description"/>
|
|
||||||
<field name="partner_id" string="Partner"/>
|
<field name="partner_id" string="Partner"/>
|
||||||
<field name="currency_id"/>
|
<field name="currency_id"/>
|
||||||
<field name="beginning_balance"/>
|
<field name="debit" sum="debit"/>
|
||||||
<field name="debit"/>
|
<field name="credit" sum="credit"/>
|
||||||
<field name="credit"/>
|
<field name="balance" sum="balance"/>
|
||||||
<field name="balance"/>
|
|
||||||
</tree>
|
</tree>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
<record id="action_ledger_bank_and_cash" model="ir.actions.act_window">
|
<record id="snk_action_ledger_bank_and_cash" model="ir.actions.act_window">
|
||||||
<field name="name">Cash and Bank Book</field>
|
<field name="name">Cash and Bank Book</field>
|
||||||
<field name="res_model">ledger.bank.and.cash</field>
|
<field name="res_model">snk.bank.and.cash.report</field>
|
||||||
<field name="view_mode">tree</field>
|
<field name="view_mode">tree</field>
|
||||||
<field name="help" type="html">
|
<field name="help" type="html">
|
||||||
<p>
|
<p>
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from odoo import models, fields, api, _
|
from odoo import models, fields, api, _, tools
|
||||||
from datetime import date, datetime, timedelta
|
from datetime import date, datetime, timedelta
|
||||||
from dateutil.relativedelta import relativedelta
|
from dateutil.relativedelta import relativedelta
|
||||||
from odoo.exceptions import ValidationError
|
from odoo.exceptions import ValidationError
|
||||||
|
@ -22,51 +22,95 @@ class WzLedgerBankAndCash(models.TransientModel):
|
||||||
raise ValidationError(_("Invalid Date ! End date should be greater than the start date"))
|
raise ValidationError(_("Invalid Date ! End date should be greater than the start date"))
|
||||||
|
|
||||||
def generate(self):
|
def generate(self):
|
||||||
beginning_balance = 0
|
tools.drop_view_if_exists(self.env.cr, 'snk_bank_and_cash_report')
|
||||||
balance = 0
|
company = self.env['res.company'].browse(1)
|
||||||
total_balance = 0
|
currency_id = company.currency_id.id
|
||||||
start = self.date_from
|
|
||||||
end = self.date_to
|
|
||||||
move_line = self.env['account.move.line'].search([('date', '>=', start), ('date', '<=', end),('account_id', 'in', self.account_ids.ids), ('move_id.state', '=', 'posted')])
|
|
||||||
bank_cash = self.env['ledger.bank.and.cash']
|
|
||||||
move_line2 = self.env['account.move.line'].search([('date', '<=', start), ('account_id', 'in', self.account_ids.ids), ('move_id.state', '=', 'posted')])
|
|
||||||
self.env.cr.execute("""
|
self.env.cr.execute("""
|
||||||
delete from ledger_bank_and_cash
|
CREATE OR REPLACE VIEW snk_bank_and_cash_report AS (
|
||||||
""")
|
|
||||||
if move_line:
|
select
|
||||||
no = 1
|
ROW_NUMBER () OVER () as id,
|
||||||
mv_line_sorted = sorted(move_line, key=lambda x: x["date"])
|
'Begining Balance' as description,
|
||||||
for account in self.account_ids:
|
null as partner_id,
|
||||||
for rec in mv_line_sorted:
|
null as account_id,
|
||||||
if rec.account_id.id == account.id:
|
{currency_id} as currency_id,
|
||||||
beginning_balance = sum(move_line2.filtered(lambda x : x.account_id.id == rec.account_id.id).mapped('balance'))
|
max(acm.date) as date,
|
||||||
if no == 1:
|
sum(acm.debit) as debit,
|
||||||
balance = beginning_balance + (rec.debit - rec.credit)
|
sum(acm.credit) as credit,
|
||||||
total_balance = balance
|
sum(acm.debit - acm.credit) as balance
|
||||||
else:
|
from account_move_line acm left join account_journal aj on acm.journal_id = aj.id
|
||||||
total_balance += rec.balance
|
where date < '{start_date}' and aj.type in ('bank', 'cash')
|
||||||
bank_cash.create({
|
|
||||||
'date': rec.date,
|
union all
|
||||||
'account_id': rec.account_id.id,
|
select
|
||||||
'move_id': rec.move_id.id,
|
ROW_NUMBER () OVER () + 1 as id,
|
||||||
'partner_id': rec.partner_id.id,
|
acm.name as description,
|
||||||
'currency_id': rec.currency_id.id,
|
null as partner_id,
|
||||||
'beginning_balance': beginning_balance,
|
acm.account_id,
|
||||||
'balance': total_balance,
|
{currency_id} as currency_id,
|
||||||
'debit': rec.debit,
|
acm.date,
|
||||||
'credit': rec.credit,
|
acm.debit,
|
||||||
})
|
acm.credit,acm.balance
|
||||||
no += 1
|
from account_move_line acm left join account_journal aj on acm.journal_id = aj.id
|
||||||
no = 1
|
where date between '{start_date}' and '{end_date}' and aj.type in ('bank', 'cash')
|
||||||
if bank_cash:
|
)""".format(start_date=self.date_from,end_date=self.date_to, currency_id=currency_id))
|
||||||
bank_cash.sorted(key=lambda r: (r.date, r.account_id))
|
|
||||||
return {
|
return {
|
||||||
'name': _("Cash and Bank Book Period %s s/d %s" %(self.date_from.strftime("%d-%m-%Y"), self.date_to.strftime("%d-%m-%Y"))),
|
'name': _('Sillo Report Bank and Cash'),
|
||||||
'view_mode': 'list',
|
|
||||||
'view_id': self.env.ref('snk_accounting_report.accounting_report_ledger_bank_and_cash_view_tree').id,
|
|
||||||
'res_model': 'ledger.bank.and.cash',
|
|
||||||
'type': 'ir.actions.act_window',
|
'type': 'ir.actions.act_window',
|
||||||
'context': {
|
'view_mode': 'tree',
|
||||||
'group_by': ['account_id'],
|
'res_model': 'snk.bank.and.cash.report',
|
||||||
}
|
'views': [(False, 'tree')],
|
||||||
|
'target': False
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# beginning_balance = 0
|
||||||
|
# balance = 0
|
||||||
|
# total_balance = 0
|
||||||
|
# start = self.date_from
|
||||||
|
# end = self.date_to
|
||||||
|
# move_line = self.env['account.move.line'].search([('date', '>=', start), ('date', '<=', end),('account_id', 'in', self.account_ids.ids), ('move_id.state', '=', 'posted')])
|
||||||
|
# bank_cash = self.env['ledger.bank.and.cash']
|
||||||
|
# move_line2 = self.env['account.move.line'].search([('date', '<=', start), ('account_id', 'in', self.account_ids.ids), ('move_id.state', '=', 'posted')])
|
||||||
|
# self.env.cr.execute("""
|
||||||
|
# delete from ledger_bank_and_cash
|
||||||
|
# """)
|
||||||
|
# if move_line:
|
||||||
|
# no = 1
|
||||||
|
# mv_line_sorted = sorted(move_line, key=lambda x: x["date"])
|
||||||
|
# for account in self.account_ids:
|
||||||
|
# for rec in mv_line_sorted:
|
||||||
|
# if rec.account_id.id == account.id:
|
||||||
|
# beginning_balance = sum(move_line2.filtered(lambda x : x.account_id.id == rec.account_id.id).mapped('balance'))
|
||||||
|
# if no == 1:
|
||||||
|
# balance = beginning_balance + (rec.debit - rec.credit)
|
||||||
|
# total_balance = balance
|
||||||
|
# else:
|
||||||
|
# total_balance += rec.balance
|
||||||
|
# bank_cash.create({
|
||||||
|
# 'date': rec.date,
|
||||||
|
# 'account_id': rec.account_id.id,
|
||||||
|
# 'move_id': rec.move_id.id,
|
||||||
|
# 'partner_id': rec.partner_id.id,
|
||||||
|
# 'currency_id': rec.currency_id.id,
|
||||||
|
# 'beginning_balance': beginning_balance,
|
||||||
|
# 'balance': total_balance,
|
||||||
|
# 'debit': rec.debit,
|
||||||
|
# 'credit': rec.credit,
|
||||||
|
# })
|
||||||
|
# no += 1
|
||||||
|
# no = 1
|
||||||
|
# if bank_cash:
|
||||||
|
# bank_cash.sorted(key=lambda r: (r.date, r.account_id))
|
||||||
|
# return {
|
||||||
|
# 'name': _("Cash and Bank Book Period %s s/d %s" %(self.date_from.strftime("%d-%m-%Y"), self.date_to.strftime("%d-%m-%Y"))),
|
||||||
|
# 'view_mode': 'list',
|
||||||
|
# 'view_id': self.env.ref('snk_accounting_report.accounting_report_ledger_bank_and_cash_view_tree').id,
|
||||||
|
# 'res_model': 'ledger.bank.and.cash',
|
||||||
|
# 'type': 'ir.actions.act_window',
|
||||||
|
# 'context': {
|
||||||
|
# 'group_by': ['account_id'],
|
||||||
|
# }
|
||||||
|
# }
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
<field name="date_from" required="1"/>
|
<field name="date_from" required="1"/>
|
||||||
<field name="date_to" required="1"/>
|
<field name="date_to" required="1"/>
|
||||||
<field name="user_type_id" invisible="1"/>
|
<field name="user_type_id" invisible="1"/>
|
||||||
<field name="account_ids" required="1" options="{'no_create' : True}" widget="many2many_tags" domain="[('user_type_id', '=', user_type_id)]"/>
|
<!-- <field name="account_ids" required="1" options="{'no_create' : True}" widget="many2many_tags" domain="[('user_type_id', '=', user_type_id)]"/> -->
|
||||||
</group>
|
</group>
|
||||||
<footer>
|
<footer>
|
||||||
<button string="Generate" name="generate" type="object" class="oe_highlight"/>
|
<button string="Generate" name="generate" type="object" class="oe_highlight"/>
|
||||||
|
|
Loading…
Reference in New Issue