OpenERP - Store Parameters and Line Fields



I'm in the process of adding three fields into the Expense form lines - product including VAT, product excluding VAT and VAT. I want these to be static fields and no calculation needs to be performed on them just yet.


Ok so, having created the .py and .xml files (legacy_expense.py, legacy_expense.xml and legacy_expense_line.py, legacy_expense_line.xml), I've been trying to get the fields related to each other but haven't been able to do so as yet. I've been looking up source code and it came to my understanding that when adding fields to a tree for the line views in forms, you have to use the store parameter in the legacy_expense.py file. However, whenever I try installing the legacy_expense_line module, I end up with a syntax error in the form of: store={^ SyntaxError: invalid syntax.


Below are the files I've created, it would be great if one of you experts out there could help me out!


legacy_expense.py



class legacy_expense(osv.osv):

_inherit = 'hr.expense.expense'

def _get_expense_from_line(self, cr, uid, ids, context=None):
return [line.expense_id.id for line in self.pool.get('hr.expense.line').browse(cr, uid, ids, context=context)]

_columns = {
'state': fields.selection([

('draft', 'New'),
('cancelled', 'Refused'),
('confirm', 'Waiting Approval'),
('done', 'Paid'),

], 'Order State', readonly= False, select=True),

'po_number':fields.char('PO Number', size = 64),

'product':fields.one2many('hr.expense.line', 'expense_id', 'Expense Lines',readonly=True, states={'draft':[('readonly',False)]} ),

store{
'hr.expense.line':(_get_expense_from_line, ['product_exc_VAT', 10)
}),

'project_id_expense': fields.many2one('project.project','Project Code'),
'project_id_account_type': fields.many2one('account.account.type','Account Type'),
'project_id_account': fields.related('project_id_account_type', 'account_name'),

'expense_client': fields.many2one('res.partner', 'Client'),
'client_expense': fields.related('expense_client', 'name'),
'dateofexpense': fields.date('Date of Expense', select=1),

}

def create(self, cr, uid, vals, context=None):
if vals.get('po_number') == None:
vals['po_number'] = self.pool.get('ir.sequence').get(cr, uid, 'hr.expense.sequence1')
return super(legacy_expense,self).create(cr, uid, vals, context)
legacy_expense()


legacy_expense.xml



<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id = "view_expenses_form_custom" model="ir.ui.view">
<field name="name">view.expenses.form.custom</field>
<field name="model">hr.expense.expense</field>
<field name="type">form</field>
<field name="inherit_id" ref="hr_expense.view_expenses_form" />
<field name="arch" type="xml">

<data>

<xpath expr="/form/sheet/notebook/page/field/form/group/group[2]/div/[@name='unit_quantity']" position="after">
<field name="productEXCVAT"/>
</xpath>

<!--xpath expr="/form/sheet/notebook/page[@string = 'Description']/field[@name='line_ids']/form/group/group[1]/field[@name='name']" position="after">
<field name="productEXCVAT"/>
</xpath-->

<header>
<button name="signal_draft_to_confirm" states="draft" string="Submit" type="workflow" groups="base.group_hr_user" />
</header>

<header>
<button name="signal_confirm_to_done" states="confirm" string="Approve Expense" type="workflow" groups="base.group_hr_user" />
</header>

<header>
<button name="signal_confirm_to_refused" states="confirm" string="Reject Expense" type="workflow" groups="base.group_hr_user" />
</header>


<header>
<button name="signal_confirm_to_draft" states="done" string="Set to draft" type="workflow" groups="base.group_hr_user" />
</header>

<header>
<button name="signal_refused_to_draft" states="cancelled" string="Set to draft" type="workflow" groups="base.group_hr_user" />
</header>


</data>

</field>
</record>
</data>
</openerp>


legacy_expense_line.py



from openerp.osv import fields, osv

class legacy_expense_line(osv.osv):

_name = 'legacy_expense_line'
_inherit = ['hr.expense.line', 'hr.expense.expense']

_columns = {

'expense_id': fields.many2one('hr.expense.expense', 'Expense', ondelete='cascade', select=True),
'product_exc_VAT':fields.float('Amount exc. VAT'),
'product_inc_VAT':fields.float('Amount inc. VAT'),
'VAT':fields.float('VAT'),
}

legacy_expense_line()


legacy_expense_line.xml



<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id = "view_expenses_line_tree_custom" model="ir.ui.view">
<field name="name">view.expenses.line.tree.custom</field>
<field name="model">hr.expense.line</field>
<field name="type">tree</field>
<field name="inherit_id" ref="hr_expense.view_expenses_form" />
<field name="arch" type="xml">


<xpath expr="/form/sheet/notebook/page[@string='Description']/field[@name='line_ids']/tree[@string='Expense Lines']/field[@name='unit_quantity']"
position = "after">
<field name="product_exc_VAT"/>

</xpath>

` <!--xpath expr="/form/sheet/notebook/page[@string = 'Description']/field[@name='line_ids']/form/group/group[2]/field[@name='unit_amount']"position="after">
<field name="product_exc_VAT"/>
</xpath-->
<!--xpath expr="/form/sheet/notebook/page/field/form/[@name='total_amount']" position="after">
<field name="product_inc_VAT"/>
</xpath>
<xpath expr="/form/sheet/notebook/page/field/form/[@name='total_amount']" position="after">
<field name="VAT"/>
</xpath-->

</field>
</record>
</data>
</openerp>


Sorry for the acres of code here, anyone who can be so kind as to point me in the right direction should have everything they need!


Thanks.


No comments:

Post a Comment