Add cost field in timesheet lines

This commit is contained in:
Jordi Esteve 2014-11-04 12:38:30 +01:00
parent 8092fc807d
commit 50bbdd2255
9 changed files with 96 additions and 2 deletions

View File

@ -3,9 +3,11 @@
# the full copyright notices and license terms.
from trytond.pool import Pool
from .work import *
from .line import *
def register():
Pool.register(
Work,
Line,
module='timesheet_cost_revenue', type_='model')

32
line.py Normal file
View File

@ -0,0 +1,32 @@
# This file is part timesheet_cost_revenue module for Tryton.
# The COPYRIGHT file at the top level of this repository contains
# the full copyright notices and license terms.
from decimal import Decimal
from trytond.model import fields
from trytond.pyson import Eval
from trytond.pool import PoolMeta
__all__ = ['Line']
__metaclass__ = PoolMeta
class Line():
__name__ = 'timesheet.line'
cost = fields.Function(fields.Numeric('Cost',
digits=(16, Eval('currency_digits', 2)),
depends=['currency_digits']), 'on_change_with_cost')
currency_digits = fields.Function(fields.Integer('Currency Digits'),
'on_change_with_currency_digits')
@fields.depends('employee', 'date', 'hours', 'work')
def on_change_with_cost(self, name=None):
if self.employee and self.hours and self.work:
return self.compute_cost()
return Decimal(0)
@fields.depends('work')
def on_change_with_currency_digits(self, name=None):
if self.work:
return self.work.currency_digits
return 2

19
line.xml Normal file
View File

@ -0,0 +1,19 @@
<?xml version="1.0"?>
<!-- This file is part timesheet_cost_revenue module for Tryton.
The COPYRIGHT file at the top level of this repository contains the full copyright notices and license terms. -->
<tryton>
<data>
<record model="ir.ui.view" id="line_view_form">
<field name="model">timesheet.line</field>
<field name="type">form</field>
<field name="inherit" ref="timesheet.line_view_form"/>
<field name="name">line_form</field>
</record>
<record model="ir.ui.view" id="line_view_tree">
<field name="model">timesheet.line</field>
<field name="type">tree</field>
<field name="inherit" ref="timesheet.line_view_tree"/>
<field name="name">line_tree</field>
</record>
</data>
</tryton>

View File

@ -2,6 +2,14 @@
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "field:timesheet.line,cost:"
msgid "Cost"
msgstr "Cost"
msgctxt "field:timesheet.line,currency_digits:"
msgid "Currency Digits"
msgstr "Decimals de moneda"
msgctxt "field:timesheet.work,list_price:"
msgid "List Price"
msgstr "Preu de venda"
@ -18,6 +26,10 @@ msgctxt "view:product.template:"
msgid "Review"
msgstr "Revisió"
msgctxt "view:timesheet.line:"
msgid "Cost"
msgstr "Cost"
msgctxt "view:timesheet.work:"
msgid "Cost & Revenue"
msgstr "Costos & Ingressos"

View File

@ -2,6 +2,14 @@
msgid ""
msgstr "Content-Type: text/plain; charset=utf-8\n"
msgctxt "field:timesheet.line,cost:"
msgid "Cost"
msgstr "Coste"
msgctxt "field:timesheet.line,currency_digits:"
msgid "Currency Digits"
msgstr "Decimales de moneda"
msgctxt "field:timesheet.work,list_price:"
msgid "List Price"
msgstr "Precio de venta"
@ -18,6 +26,10 @@ msgctxt "view:product.template:"
msgid "Review"
msgstr "Revisión"
msgctxt "view:timesheet.line:"
msgid "Cost"
msgstr "Coste"
msgctxt "view:timesheet.work:"
msgid "Cost & Revenue"
msgstr "Costes & Ingresos"

View File

@ -5,3 +5,4 @@ depends:
timesheet_cost
xml:
work.xml
line.xml

9
view/line_form.xml Normal file
View File

@ -0,0 +1,9 @@
<?xml version="1.0"?>
<!-- This file is part production_cost_timesheet module for Tryton.
The COPYRIGHT file at the top level of this repository contains the full copyright notices and license terms. -->
<data>
<xpath expr="/form/field[@name=&quot;description&quot;]" position="after">
<label name="cost"/>
<field name="cost"/>
</xpath>
</data>

8
view/line_tree.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0"?>
<!-- This file is part production_cost_timesheet module for Tryton.
The COPYRIGHT file at the top level of this repository contains the full copyright notices and license terms. -->
<data>
<xpath expr="/tree/field[@name=&quot;description&quot;]" position="after">
<field name="cost" sum="Cost"/>
</xpath>
</data>

View File

@ -2,8 +2,7 @@
<!-- This file is part production_cost_timesheet module for Tryton.
The COPYRIGHT file at the top level of this repository contains the full copyright notices and license terms. -->
<data>
<xpath expr="/form/field[@name=&quot;company&quot;]"
position="after">
<xpath expr="/form/field[@name=&quot;company&quot;]" position="after">
<separator string="Cost &amp; Revenue" colspan="4" id="cost_revenue"/>
<label name="product"/>
<field name="product"/>