[IMP] query by journal account
parent
aec988c6cc
commit
a209f2a6b9
|
@ -14,7 +14,15 @@ class WzLedgerBankAndCash(models.TransientModel):
|
||||||
date_to = fields.Date("To Date")
|
date_to = fields.Date("To Date")
|
||||||
account_ids = fields.Many2many('account.account', string='Account')
|
account_ids = fields.Many2many('account.account', string='Account')
|
||||||
user_type_id = fields.Many2one('account.account.type', string='User Type', default=lambda self:self.default_user_type())
|
user_type_id = fields.Many2one('account.account.type', string='User Type', default=lambda self:self.default_user_type())
|
||||||
|
company_id = fields.Many2one('res.company', default=lambda self: self.env.company)
|
||||||
|
journal_ids = fields.Many2many('account.journal')
|
||||||
|
|
||||||
|
@api.onchange('journal_ids')
|
||||||
|
def onchange_journal_ids(self):
|
||||||
|
if not self.journal_ids:
|
||||||
|
return
|
||||||
|
acc_ids = [x.default_account_id.id for x in self.journal_ids]
|
||||||
|
self.account_ids = acc_ids
|
||||||
@api.constrains("date_from", "date_to")
|
@api.constrains("date_from", "date_to")
|
||||||
def _check_filtered(self):
|
def _check_filtered(self):
|
||||||
for rec in self:
|
for rec in self:
|
||||||
|
@ -23,28 +31,35 @@ class WzLedgerBankAndCash(models.TransientModel):
|
||||||
|
|
||||||
def generate(self):
|
def generate(self):
|
||||||
tools.drop_view_if_exists(self.env.cr, 'snk_bank_and_cash_report')
|
tools.drop_view_if_exists(self.env.cr, 'snk_bank_and_cash_report')
|
||||||
company = self.env['res.company'].browse(1)
|
company_id = self.company_id
|
||||||
currency_id = company.currency_id.id
|
currency_id = company_id.currency_id.id
|
||||||
|
journal_banks = self.env['account.journal'].search([('type','=','bank')])
|
||||||
|
account_banks = [str(x.default_account_id.id) for x in journal_banks]
|
||||||
|
print(account_banks)
|
||||||
|
n_account = len(account_banks)
|
||||||
|
str_account = ",".join(account_banks)
|
||||||
|
print(str_account)
|
||||||
|
|
||||||
|
|
||||||
self.env.cr.execute("""
|
self.env.cr.execute("""
|
||||||
CREATE OR REPLACE VIEW snk_bank_and_cash_report AS (
|
CREATE OR REPLACE VIEW snk_bank_and_cash_report AS (
|
||||||
|
|
||||||
select
|
select
|
||||||
ROW_NUMBER () OVER () as id,
|
ROW_NUMBER () OVER () as id,
|
||||||
'Begining Balance' as description,
|
'Begining Balance' as description,
|
||||||
null as partner_id,
|
null as partner_id,
|
||||||
null as account_id,
|
acm.account_id as account_id,
|
||||||
{currency_id} as currency_id,
|
{currency_id} as currency_id,
|
||||||
max(acm.date) as date,
|
max(acm.date) as date,
|
||||||
sum(acm.debit) as debit,
|
sum(acm.debit) as debit,
|
||||||
sum(acm.credit) as credit,
|
sum(acm.credit) as credit,
|
||||||
sum(acm.debit - acm.credit) as balance
|
sum(acm.debit - acm.credit) as balance
|
||||||
from account_move_line acm left join account_journal aj on acm.journal_id = aj.id
|
from account_move_line acm left join account_journal aj on acm.journal_id = aj.id
|
||||||
where date < '{start_date}' and aj.type in ('bank', 'cash')
|
left join account_account account on acm.account_id = account.id
|
||||||
|
where date < '{start_date}' and aj.type in ('bank', 'cash') and account.id in ({str_account})
|
||||||
|
group by acm.account_id
|
||||||
union all
|
union all
|
||||||
select
|
select
|
||||||
ROW_NUMBER () OVER () + 1 as id,
|
ROW_NUMBER () OVER () + {n} as id,
|
||||||
acm.name as description,
|
acm.name as description,
|
||||||
null as partner_id,
|
null as partner_id,
|
||||||
acm.account_id,
|
acm.account_id,
|
||||||
|
@ -53,8 +68,9 @@ class WzLedgerBankAndCash(models.TransientModel):
|
||||||
acm.debit,
|
acm.debit,
|
||||||
acm.credit,acm.balance
|
acm.credit,acm.balance
|
||||||
from account_move_line acm left join account_journal aj on acm.journal_id = aj.id
|
from account_move_line acm left join account_journal aj on acm.journal_id = aj.id
|
||||||
where date between '{start_date}' and '{end_date}' and aj.type in ('bank', 'cash')
|
left join account_account account on acm.account_id = account.id
|
||||||
)""".format(start_date=self.date_from,end_date=self.date_to, currency_id=currency_id))
|
where date between '{start_date}' and '{end_date}' and aj.type in ('bank', 'cash') and account.id in ({str_account})
|
||||||
|
)""".format(start_date=self.date_from,end_date=self.date_to, currency_id=currency_id, n=n_account,str_account=str_account))
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'name': _('Sillo Report Bank and Cash'),
|
'name': _('Sillo Report Bank and Cash'),
|
||||||
|
|
|
@ -11,6 +11,9 @@
|
||||||
<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="company_id"/>
|
||||||
|
<field name="journal_ids" widget="many2many_tags"/>
|
||||||
|
<field name="account_ids" widget="many2many_tags"/>
|
||||||
<!-- <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>
|
||||||
|
|
Loading…
Reference in New Issue