Updated report and expenses

This commit is contained in:
projectsodoo 2020-12-20 14:27:45 +05:30
parent 3bad728a41
commit 452913d6dd
5 changed files with 16 additions and 97 deletions

View File

@ -27,13 +27,16 @@ class BudgetAmtAnalysis(models.Model):
PRO.id AS project_id,
PRO.partner_id AS partner_id,
AAL.employee_id AS employee_id,
PRO.budgeted_hours AS budgeted_revenue,
sum(AAL.amount) AS actual_revenue
--PRO.budgeted_hours AS budgeted_revenue,
--sum(AAL.amount) AS budgeted_revenue
SO.amount_total AS budgeted_revenue,
SO.amount_total - sum(AAL.amount) AS actual_revenue
FROM project_project PRO
LEFT JOIN sale_order SO ON PRO.sale_order_id = SO.id
LEFT JOIN account_analytic_account AA ON PRO.analytic_account_id = AA.id
LEFT JOIN account_analytic_line AAL ON AAL.account_id = AA.id
WHERE AAL.amount < 0.0 AND AAL.project_id IS NOT NULL AND PRO.active = 't' AND PRO.allow_timesheets = 't'
group by Pro.id, PRO.partner_id, AAL.employee_id, Pro.budgeted_hours, AAL.unit_amount
group by Pro.id, PRO.partner_id, AAL.employee_id, Pro.budgeted_hours, AAL.unit_amount, so.amount_total
)""" % (self._table,))

View File

@ -39,15 +39,13 @@ class ProjectCreateExpense(models.TransientModel):
percentage_rate = fields.Float(string="Percentage (%)")
expenses_amt = fields.Float(string="Amount", digits=(6, 2), required=True)
@api.onchange('ispercentage', 'expenses_from', 'percentage_rate', 'per_from_amt')
@api.onchange('ispercentage', 'expenses_from')
def onchange_ispercentage(self):
expense_amount = 0
active_id = self._context.get('active_id')
if self.ispercentage and self.expenses_from:
profit = dict.fromkeys(['invoiced', 'to_invoice'], 0.0)
profitability_raw_data = self.env['project.profitability.report'].read_group([('project_id', '=', active_id)],
['project_id', 'amount_untaxed_to_invoice', 'amount_untaxed_invoiced'], ['project_id'])
print("profitability_raw_dataprofitability_raw_data", profitability_raw_data)
for data in profitability_raw_data:
profit['invoiced'] += data.get('amount_untaxed_invoiced', 0.0)
profit['to_invoice'] += data.get('amount_untaxed_to_invoice', 0.0)
@ -55,8 +53,14 @@ class ProjectCreateExpense(models.TransientModel):
self.per_from_amt = profit['invoiced']
if self.expenses_from == 'to_invoice':
self.per_from_amt = profit['to_invoice']
if self.percentage_rate > 0.0 and self.per_from_amt > 0.0:
expense_amount = self.per_from_amt * (self.percentage_rate / 100)
#if self.percentage_rate > 0.0 and self.per_from_amt > 0.0:
#expense_amount = self.per_from_amt * (self.percentage_rate / 100)
#self.expenses_amt = expense_amount
@api.onchange('ispercentage', 'per_from_amt', 'percentage_rate')
def onchange_percentage_rate(self):
if self.percentage_rate > 0.0 and self.per_from_amt > 0.0:
expense_amount = self.per_from_amt * (self.percentage_rate / 100)
self.expenses_amt = expense_amount

View File

@ -14,7 +14,7 @@
<field name="description"/>
</group>
<group col="4" colspan="2">
<field name="ispercentage"/>
<field name="ispercentage"/>
<field name="expenses_from" attrs="{'invisible':[('ispercentage','=',False)]}"/>
<field name="per_from_amt" attrs="{'invisible':[('ispercentage','=',False)]}"/>
<field name="percentage_rate" attrs="{'invisible':[('ispercentage','=',False)]}"/>

View File

@ -1,58 +0,0 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, fields, models, _
from odoo.exceptions import UserError
class ProjectCreateExpenses(models.TransientModel):
_name = 'project.create.expenses'
_description = "Create Expenses from project"
@api.model
def default_get(self, fields):
result = super(ProjectCreateInvoice, self).default_get(fields)
active_model = self._context.get('active_model')
if active_model != 'project.project':
raise UserError(_('You can only apply this action from a project.'))
active_id = self._context.get('active_id')
if 'project_id' in fields and active_id:
result['project_id'] = active_id
return result
project_id = fields.Many2one('project.project', "Project", help="Project to make billable", required=True)
_candidate_orders = fields.Many2many('sale.order', compute='_compute_candidate_orders')
sale_order_id = fields.Many2one(
'sale.order', string="Choose the Sales Order to invoice", required=True,
domain="[('id', 'in', _candidate_orders)]"
)
amount_to_invoice = fields.Monetary("Amount to invoice", compute='_compute_amount_to_invoice', currency_field='currency_id', help="Total amount to invoice on the sales order, including all items (services, storables, expenses, ...)")
currency_id = fields.Many2one(related='sale_order_id.currency_id', readonly=True)
@api.depends('project_id.tasks.sale_line_id.order_id.invoice_status')
def _compute_candidate_orders(self):
for p in self:
p._candidate_orders = p.project_id\
.mapped('tasks.sale_line_id.order_id')\
.filtered(lambda so: so.invoice_status == 'to invoice')
@api.depends('sale_order_id')
def _compute_amount_to_invoice(self):
for wizard in self:
amount_untaxed = 0.0
amount_tax = 0.0
for line in wizard.sale_order_id.order_line.filtered(lambda sol: sol.invoice_status == 'to invoice'):
amount_untaxed += line.price_reduce * line.qty_to_invoice
amount_tax += line.price_tax
wizard.amount_to_invoice = amount_untaxed + amount_tax
def action_create_invoice(self):
if not self.sale_order_id and self.sale_order_id.invoice_status != 'to invoice':
raise UserError(_("The selected Sales Order should contain something to invoice."))
action = self.env["ir.actions.actions"]._for_xml_id("sale.action_view_sale_advance_payment_inv")
action['context'] = {
'active_ids': self.sale_order_id.ids
}
return action

View File

@ -1,30 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<record id="project_create_expense_view_form" model="ir.ui.view">
<field name="name">project.create.expense.view.form</field>
<field name="model">project.create.expense</field>
<field name="arch" type="xml">
<form string="Create Expense from Project">
<group>
<field name="project_id" readonly="1"/>
<!--<field name="sale_order_id" options="{'no_create_edit': True}" context="{'sale_show_partner_name': True}"/>-->
<field name="amount_to_invoice"/>
</group>
<footer>
<button string="Create Expense" type="object" name="action_create_project_expense" class="oe_highlight"/>
<button string="Cancel" special="cancel" type="object" class="btn btn-secondary oe_inline"/>
</footer>
</form>
</field>
</record>
<record id="project_project_action_multi_create_project_expense" model="ir.actions.act_window">
<field name="name">Create Expense</field>
<field name="res_model">project.create.expense</field>
<field name="view_mode">form</field>
<field name="view_id" ref="project_create_expense_view_form"/>
<field name="target">new</field>
</record>
</odoo>