Created
February 17, 2017 10:44
-
-
Save nhomar/d526d558d6ca15a104d0dfeee8b4be16 to your computer and use it in GitHub Desktop.
hr_timesheet_invoiceable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
from odoo import fields, models, api | |
class HrTimesheetInvoiceFactor(models.Model): | |
_name = "hr_timesheet_invoice.factor" | |
_description = "Invoice Rate" | |
_order = 'factor' | |
name = fields.Char('Internal Name', required=True, translate=True) | |
customer_name = fields.Char('Name', help="Label for the customer") | |
factor = fields.Float( | |
'Discount (%)', | |
default=0.0, | |
help="Discount in percentage") | |
class AccountAnalyticLine(models.Model): | |
_inherit = 'account.analytic.line' | |
to_invoice = fields.Many2one( | |
'hr_timesheet_invoice.factor', | |
'Invoiceable', | |
default=lambda s: s.env['hr_timesheet_invoice.factor'].search( | |
[], order='factor asc', limit=1), | |
help="It allows to set the discount while making invoice, keep" | |
" empty if the activities should not be invoiced.") | |
invoiceables_hours = fields.Float( | |
'Invoiceable Hours', | |
compute="_compute_invoiceables_hours", | |
help='Total hours to charge') | |
invoice_id = fields.Many2one( | |
'account.invoice', | |
'Invoice', | |
ondelete="set null", | |
copy=False) | |
@api.depends('to_invoice', 'unit_amount') | |
def _compute_invoiceables_hours(self): | |
for line in self: | |
hours = line.unit_amount | |
if line.to_invoice: | |
hours -= (hours * line.to_invoice.factor / 100.0) | |
line.invoiceables_hours = hours |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<openerp> | |
<data> | |
<record id="account_analytic_line_invoiceable_lines" model="ir.ui.view"> | |
<field name="name">account.analytic.line.invoiceable.lines</field> | |
<field name="model">account.analytic.line</field> | |
<field name="inherit_id" ref="hr_timesheet.hr_timesheet_line_tree"/> | |
<field name="arch" type="xml"> | |
<xpath expr="//field[@name='unit_amount']" position="after"> | |
<field name="to_invoice"/> | |
<field name="invoiceables_hours" sum="Total invoiceable time" widget="float_time"/> | |
</xpath> | |
</field> | |
</record> | |
<record id="account_analytic_line_invoiceable_lines2" model="ir.ui.view"> | |
<field name="name">account.analytic.line.invoiceable.lines2</field> | |
<field name="model">account.analytic.line</field> | |
<field name="inherit_id" ref="timesheet_grid.view_timesheet_list"/> | |
<field name="arch" type="xml"> | |
<xpath expr="//field[@name='unit_amount']" position="after"> | |
<field name="to_invoice"/> | |
<field name="invoiceables_hours" sum="Total invoiceable time" widget="float_time"/> | |
</xpath> | |
</field> | |
</record> | |
</data> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Cool, thanks!