mirror of
https://github.com/bringout/oca-ocb-accounting.git
synced 2026-04-23 03:42:00 +02:00
19.0 vanilla
This commit is contained in:
parent
ba20ce7443
commit
768b70e05e
2357 changed files with 1057103 additions and 712486 deletions
|
|
@ -15,91 +15,64 @@ class AccountAnalyticAccount(models.Model):
|
|||
compute='_compute_vendor_bill_count',
|
||||
)
|
||||
|
||||
debit = fields.Monetary(groups='account.group_account_readonly')
|
||||
credit = fields.Monetary(groups='account.group_account_readonly')
|
||||
|
||||
@api.depends('line_ids')
|
||||
def _compute_invoice_count(self):
|
||||
sale_types = self.env['account.move'].get_sale_types(include_receipts=True)
|
||||
|
||||
query = self.env['account.move.line']._search([
|
||||
('parent_state', '=', 'posted'),
|
||||
('move_id.move_type', 'in', sale_types),
|
||||
])
|
||||
query.add_where(
|
||||
'account_move_line.analytic_distribution ?| %s',
|
||||
[[str(account_id) for account_id in self.ids]],
|
||||
data = self.env['account.move.line']._read_group(
|
||||
[
|
||||
('parent_state', '=', 'posted'),
|
||||
('move_id.move_type', 'in', sale_types),
|
||||
('analytic_distribution', 'in', self.ids),
|
||||
],
|
||||
['analytic_distribution'],
|
||||
['__count'],
|
||||
)
|
||||
|
||||
query.order = None
|
||||
query_string, query_param = query.select(
|
||||
'jsonb_object_keys(account_move_line.analytic_distribution) as account_id',
|
||||
'COUNT(DISTINCT(account_move_line.move_id)) as move_count',
|
||||
)
|
||||
query_string = f"{query_string} GROUP BY jsonb_object_keys(account_move_line.analytic_distribution)"
|
||||
|
||||
self._cr.execute(query_string, query_param)
|
||||
data = {int(record.get('account_id')): record.get('move_count') for record in self._cr.dictfetchall()}
|
||||
data = {int(account_id): move_count for account_id, move_count in data}
|
||||
for account in self:
|
||||
account.invoice_count = data.get(account.id, 0)
|
||||
|
||||
@api.depends('line_ids')
|
||||
def _compute_vendor_bill_count(self):
|
||||
purchase_types = self.env['account.move'].get_purchase_types(include_receipts=True)
|
||||
|
||||
query = self.env['account.move.line']._search([
|
||||
('parent_state', '=', 'posted'),
|
||||
('move_id.move_type', 'in', purchase_types),
|
||||
])
|
||||
query.add_where(
|
||||
'account_move_line.analytic_distribution ?| %s',
|
||||
[[str(account_id) for account_id in self.ids]],
|
||||
data = self.env['account.move.line']._read_group(
|
||||
[
|
||||
('parent_state', '=', 'posted'),
|
||||
('move_id.move_type', 'in', purchase_types),
|
||||
('analytic_distribution', 'in', self.ids),
|
||||
],
|
||||
['analytic_distribution'],
|
||||
['__count'],
|
||||
)
|
||||
|
||||
query.order = None
|
||||
query_string, query_param = query.select(
|
||||
'jsonb_object_keys(account_move_line.analytic_distribution) as account_id',
|
||||
'COUNT(DISTINCT(account_move_line.move_id)) as move_count',
|
||||
)
|
||||
query_string = f"{query_string} GROUP BY jsonb_object_keys(account_move_line.analytic_distribution)"
|
||||
|
||||
self._cr.execute(query_string, query_param)
|
||||
data = {int(record.get('account_id')): record.get('move_count') for record in self._cr.dictfetchall()}
|
||||
data = {int(account_id): move_count for account_id, move_count in data}
|
||||
for account in self:
|
||||
account.vendor_bill_count = data.get(account.id, 0)
|
||||
|
||||
def action_view_invoice(self):
|
||||
self.ensure_one()
|
||||
query = self.env['account.move.line']._search([('move_id.move_type', 'in', self.env['account.move'].get_sale_types())])
|
||||
query.order = None
|
||||
query.add_where('analytic_distribution ? %s', [str(self.id)])
|
||||
query_string, query_param = query.select('DISTINCT account_move_line.move_id')
|
||||
self._cr.execute(query_string, query_param)
|
||||
move_ids = [line.get('move_id') for line in self._cr.dictfetchall()]
|
||||
result = {
|
||||
account_move_lines = self.env['account.move.line'].search_fetch([
|
||||
('move_id.move_type', 'in', self.env['account.move'].get_sale_types()),
|
||||
('analytic_distribution', 'in', self.ids),
|
||||
], ['move_id'])
|
||||
return {
|
||||
"type": "ir.actions.act_window",
|
||||
"res_model": "account.move",
|
||||
"domain": [('id', 'in', move_ids)],
|
||||
"domain": [('id', 'in', account_move_lines.move_id.ids)],
|
||||
"context": {"create": False, 'default_move_type': 'out_invoice'},
|
||||
"name": _("Customer Invoices"),
|
||||
'view_mode': 'tree,form',
|
||||
'view_mode': 'list,form',
|
||||
}
|
||||
return result
|
||||
|
||||
def action_view_vendor_bill(self):
|
||||
self.ensure_one()
|
||||
query = self.env['account.move.line']._search([('move_id.move_type', 'in', self.env['account.move'].get_purchase_types())])
|
||||
query.order = None
|
||||
query.add_where('analytic_distribution ? %s', [str(self.id)])
|
||||
query_string, query_param = query.select('DISTINCT account_move_line.move_id')
|
||||
self._cr.execute(query_string, query_param)
|
||||
move_ids = [line.get('move_id') for line in self._cr.dictfetchall()]
|
||||
result = {
|
||||
account_move_lines = self.env['account.move.line'].search_fetch([
|
||||
('move_id.move_type', 'in', self.env['account.move'].get_purchase_types(include_receipts=True)),
|
||||
('analytic_distribution', 'in', self.ids),
|
||||
], ['move_id'])
|
||||
return {
|
||||
"type": "ir.actions.act_window",
|
||||
"res_model": "account.move",
|
||||
"domain": [('id', 'in', move_ids)],
|
||||
"domain": [('id', 'in', account_move_lines.move_id.ids)],
|
||||
"context": {"create": False, 'default_move_type': 'in_invoice'},
|
||||
"name": _("Vendor Bills"),
|
||||
'view_mode': 'tree,form',
|
||||
'view_mode': 'list,form',
|
||||
}
|
||||
return result
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue