Browse Source

[IMP] Hide release capital request from the invoice total computation of

the smart button on partner form and from its corresponding view when
clicking on it.
pull/1/head
houssine 8 years ago
parent
commit
f179e9e7b9
  1. 2
      easy_my_coop/__init__.py
  2. 43
      easy_my_coop/models/partner.py
  3. 1
      easy_my_coop/report/__init__.py
  4. 13
      easy_my_coop/report/account_invoice_report.py
  5. 10
      easy_my_coop/view/account_invoice_view.xml

2
easy_my_coop/__init__.py

@ -1,3 +1,3 @@
from . import models from . import models
from . import controllers from . import controllers
#import wizard
from . import report

43
easy_my_coop/models/partner.py

@ -1,9 +1,50 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from openerp import api, fields, models, _ from openerp import api, fields, models, _
class res_partner(models.Model):
class ResPartner(models.Model):
_inherit = 'res.partner' _inherit = 'res.partner'
@api.multi
def _invoice_total(self):
account_invoice_report = self.env['account.invoice.report']
if not self.ids:
self.total_invoiced = 0.0
return True
user_currency_id = self.env.user.company_id.currency_id.id
all_partners_and_children = {}
all_partner_ids = []
for partner in self:
# price_total is in the company currency
all_partners_and_children[partner] = self.search([('id', 'child_of', partner.id)]).ids
all_partner_ids += all_partners_and_children[partner]
# searching account.invoice.report via the orm is comparatively expensive
# (generates queries "id in []" forcing to build the full table).
# In simple cases where all invoices are in the same currency than the user's company
# access directly these elements
# generate where clause to include multicompany rules
where_query = account_invoice_report._where_calc([
('partner_id', 'in', all_partner_ids), ('state', 'not in', ['draft', 'cancel']), ('company_id', '=', self.env.user.company_id.id),
('type', 'in', ('out_invoice', 'out_refund')),
('release_capital_request','=',False),
])
account_invoice_report._apply_ir_rules(where_query, 'read')
from_clause, where_clause, where_clause_params = where_query.get_sql()
# price_total is in the company currency
query = """
SELECT SUM(price_total) as total, partner_id
FROM account_invoice_report account_invoice_report
WHERE %s
GROUP BY partner_id
""" % where_clause
self.env.cr.execute(query, where_clause_params)
price_totals = self.env.cr.dictfetchall()
for partner, child_ids in all_partners_and_children.items():
partner.total_invoiced = sum(price['total'] for price in price_totals if price['partner_id'] in child_ids)
@api.multi @api.multi
def _get_share_type(self): def _get_share_type(self):
share_type_list = [('','')] share_type_list = [('','')]

1
easy_my_coop/report/__init__.py

@ -0,0 +1 @@
from . import account_invoice_report

13
easy_my_coop/report/account_invoice_report.py

@ -0,0 +1,13 @@
# -*- coding: utf-8 -*-
from openerp import api, fields, models, _
class AccountInvoiceReport(models.Model):
_inherit = "account.invoice.report"
release_capital_request = fields.Boolean(string="Release capital request")
def _select(self):
return super(AccountInvoiceReport, self)._select() + ", sub.release_capital_request as release_capital_request"
def _sub_select(self):
return super(AccountInvoiceReport, self)._sub_select() + ", ai.release_capital_request as release_capital_request"

10
easy_my_coop/view/account_invoice_view.xml

@ -74,5 +74,15 @@
</field> </field>
</record> </record>
<record id="account.action_invoice_refund_out_tree" model="ir.actions.act_window">
<field name="name">Invoices</field>
<field name="res_model">account.invoice</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form,kanban,calendar,graph,pivot</field>
<field name="view_id" ref="account.invoice_tree"/>
<field name="domain">[('type','in', ['out_invoice', 'out_refund']), ('state', 'not in', ['draft', 'cancel']),('release_capital_request','=',False)]</field>
<field name="context">{'default_type':'out_invoice', 'type':'out_invoice', 'journal_type': 'sale'}</field>
<field name="search_view_id" ref="account.view_account_invoice_filter"/>
</record>
</data> </data>
</openerp> </openerp>
Loading…
Cancel
Save