I'm new to openerp.I want to add new fields to inherited custom module and at the same time i want to remove unwanted fields in newly created Custom Module.I want add some details like Mothername and Fathername and also i want to hide unwanted details like job position and website.Can any one please tell me.
Thanks in advance
My Code :
init.py
import lead
openerp.py
{
'name': 'Lead Information',
'version': '0.1',
'category': 'Tools',
'description': """This module is Lead information.""",
'author': 'Nitesh',
'website': '',
'depends': ['base'],
'init_xml': ['lead_view.xml'],
'update_xml': [],
'demo_xml': [],
'installable': True,
'active': True,
'application': True
}
lead.py
from osv import osv
from osv import fields
class cus(osv.osv):
_name = "lead.partner"
_inherit = "res.partner"
_description = "This table is for keeping lead data"
_columns = {
'mothername': fields.char('Mother Name',size=10,required=True)
}
lead_view.xml
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<!-- ===================== This is tree layout =============================-->
<record id="lead_tree" model="ir.ui.view">
<field name="name">Lead</field>
<field name="model">lead.partner</field>
<field name="arch" type="xml">
<field name="mothername"/>
<field name="website" position="attributes"><!--removed / from the end-->
<attribute name="invisible">True</attribute>
</field>
</field>
</record>
<!-- ========================This is Form layout===============================-->
<record id="lead_form" model="ir.ui.view">
<field name="name">Lead</field>
<field name="model">lead.partner</field>
<field name="arch" type="xml">
<field name="mothername"/>
<field name="function" position="attributes"><!--removed / from the end-->
<attribute name="invisible">True</attribute>
</field>
</field>
</record>
<!-- ========================= Action Layout ============================= -->
<record id="action_lead" model="ir.actions.act_window">
<field name="name">Lead</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">res.partner</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="view_id" ref="lead_tree"/>
</record>
<!-- ===========================Menu Settings=========================== -->
<menuitem name = "Lead" id = "menu_lis_lab" action="action_lead"/>
</data>
</openerp>
If you want to remove any field than use this,
<field name="website" position="replace"/>
you can remove fields which are from parent view. this is right way.
You can use these values in the position attribute:
inside (default): your values will be appended inside the tag
after: add the content after the tag
before: add the content before the tag
replace: replace the content of the tag.
for more details - http://openerp-server.readthedocs.org/en/latest/03_module_dev_03.html
Hope this would be helpful to you.
First add create the fields in *.py file and upgrade your custom module and later add the fields in *.xml and upgrade the module again,it will work perfectly fine.Now i can add the fields and hide the unwanted fields in my custom module
ex:I want add Mothername and Father name below "JObPostion" and to hide website field
the below is the working code
My code
lead_view.xml
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<!-- ===================== This is tree layout =============================-->
<record id="lead_tree" model="ir.ui.view">
<field name="name">Lead</field>
<field name="model">res.partner</field>
<field name="arch" type="xml">
<tree string="lead">
<field name = "name"/>
</tree>
</field>
</record>
<!-- ========================This is Form layout===============================-->
<record id="view_res_partner_inherited" model="ir.ui.view">
<field name="name">view.res.partner.inherited</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form" />
<field name="arch" type="xml">
<data>
<field name="website" position="replace"/>
<field name="function" position="after">
<field name="mothername"/>
<field name="fathername"/>
</field>
</data>
</field>
</record>
<!-- ========================= Action Layout ============================= -->
<record id="action_lead" model="ir.actions.act_window">
<field name="name">Lead</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">res.partner</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="view_id" ref="lead_tree"/>
</record>
<!-- ===========================Menu Settings=========================== -->
<menuitem name = "Lead" id = "menu_lis_lab" action="action_lead"/>
</data>
</openerp>
and
lead.py
from osv import osv
from osv import fields
class res_partner(osv.osv):
_inherit = "res.partner"
_description = "adding fields to res.partner"
_columns = {
'mothername': fields.char('Mother Name',size=64,required=True),
'fathername': fields.char('Father Name',size=64,required=True)
}
Related
I am using Odoo 11 and get the below error when installing a custom module. This is a module that is working in Odoo 10. I cant figure out where I am going wrong.
Field `custom_discount_product_id2` does not exist
Error context:
View `pos.config.custom.discount.form.view`
[view_id: 1029, xml_id: pos_custom.view_pos_config_form_custom_discount, model: pos.config, parent_id: 730]
None" while parsing /odoo/custom/addons/pos_custom/views/pos_custom_sale_view.xml:22, near
<record model="ir.ui.view" id="view_pos_config_form_custom_discount">
<field name="name">pos.config.custom.discount.form.view</field>
<field name="model">pos.config</field>
<field name="inherit_id" ref="point_of_sale.pos_config_view_form"/>
<field name="arch" type="xml">
<xpath expr="//div[#id='title']" position="after">
<group string="Custom Discount">
<field name="custom_discount_product_id2"/>
</group>
</xpath>
</field>
</record>
Here is my sale.py file
from odoo import api, fields, models
class PosConfig(models.Model):
_inherit = 'pos.config'
custom_discount_product_id2 = fields.Many2one('product.product', string='Custom Discount Product')
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
And here is the view file.
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record model="ir.ui.view" id="view_pos_config_form_custom_discount">
<field name="name">pos.config.custom.discount.form.view</field>
<field name="model">pos.config</field>
<field name="inherit_id" ref="point_of_sale.pos_config_view_form"/>
<field name="arch" type="xml">
<xpath expr="//div[#id='title']" position="after">
<group string="Custom Discount">
<field name="custom_discount_product_id2" />
</group>
</xpath>
</field>
</record>
</data>
</openerp>
I've checked other modules, restarted server, but for some reason the field is not created.
Make sure <your_module>/__init__.py contains:
from . import models
and that <your_module>/models/__init__.py contains:
from . import sale
In Odoo 8, we could import CSV data for "Account moves" and "Account move lines".
I'm migrating to Odoo 10 : i found how to import "Account moves" but where can i import the line of my moves (there's no "Import" button on the view of Account move lines) ?
Thanx.
Christophe
In account.move.line default tree view create='false' is set.
If in tree view create='false' is set then odoo will hide Create and Import button.
The following is odoo default view.
<record id="view_move_line_tree" model="ir.ui.view">
<field name="name">account.move.line.tree</field>
<field name="model">account.move.line</field>
<field eval="1" name="priority"/>
<field name="arch" type="xml">
<tree string="Journal Items" create="false">
<field name="date"/>
<field name="move_id" required="0"/>
<field name="journal_id" options='{"no_open":True}'/>
<field name="name"/>
<field name="ref"/>
<field name="statement_id" invisible="1"/>
<field name="partner_id"/>
<field name="account_id" options='{"no_open":True}' domain="[('company_id', '=', company_id)]"/>
<field name="analytic_account_id" groups="analytic.group_analytic_accounting"/>
<field name="reconciled" invisible="1"/>
<field name="full_reconcile_id"/>
<field name="debit" sum="Total Debit"/>
<field name="credit" sum="Total Credit"/>
<field name="amount_currency" readonly="True" groups="base.group_multi_currency"/>
<field name="currency_id" readonly="True" invisible="1" />
<field name="date_maturity"/>
<field name="company_currency_id" invisible="1"/>
<field name="company_id" invisible="1"/>
</tree>
</field>
</record>
You can override above Tree view in your module and remove create='false'.
<record id="account.view_move_line_tree" model="ir.ui.view">
<field name="name">account.move.line.tree</field>
<field name="model">account.move.line</field>
<field eval="1" name="priority"/>
<field name="arch" type="xml">
<tree string="Journal Items">
<field name="date"/>
<field name="move_id" required="0"/>
<field name="journal_id" options='{"no_open":True}'/>
<field name="name"/>
<field name="ref"/>
<field name="statement_id" invisible="1"/>
<field name="partner_id"/>
<field name="account_id" options='{"no_open":True}' domain="[('company_id', '=', company_id)]"/>
<field name="analytic_account_id" groups="analytic.group_analytic_accounting"/>
<field name="reconciled" invisible="1"/>
<field name="full_reconcile_id"/>
<field name="debit" sum="Total Debit"/>
<field name="credit" sum="Total Credit"/>
<field name="amount_currency" readonly="True" groups="base.group_multi_currency"/>
<field name="currency_id" readonly="True" invisible="1" />
<field name="date_maturity"/>
<field name="company_currency_id" invisible="1"/>
<field name="company_id" invisible="1"/>
</tree>
</field>
</record>
After that You can import CSV file.
You can import account.move.line & account.move in same file, I have attached import format.
You can export any existing account move from Action in tree view and select all required field.Just export it.
If you want to import account.move.line and account.move using different file then you must inherit account.move.line create method and set check_move_validity is False.
if self._context.get('check_move_validity', True):
move.with_context(context)._post_validate()
Above condition is odoo base module account.move.line create method condtion.When account.move.line is create at that time system is checking if check_move_validity is False then system will not try to reconcile single move line.
You need to inherit create and write method in custom module,after that line by line import work as well.
#api.model
def create(self, vals):
move_line = super(AccountMoveLine, self.with_context(check_move_validity=False)).create(vals)
return move_line
#api.multi
def write(self, vals):
move_line = super(AccountMoveLine, self.with_context(check_move_validity=False)).write(vals)
return move_line
This may help you.
for information i am on odoov11.0c
all is based on ids,when you import data remember that account_account account_move and account_move_line are linked and see terms used directly on model class
from an xls files you can import from the standard menu account_move and account move line using those first line cells name:
Journal
Date
id
line_ids/partner_id
Number
reference
line_ids/debit
line_ids/credit
narration
line_ids/matching_number/Number
line_ids/due date
line_ids/counterpart
line_ids/account_id
Status
Hope this help
I created a custom module and created a new user in odoo with email :1#1.com and password :1234 .When i try to login with new user webpage show this error
:"The server encountered an internal error and was unable to complete
your request. Either the server is overloaded or there is an error in
the application."
and in eclipe show this error:
"AccessError: ('AccessError', u'Sorry, you are not allowed to access
this document. Only users with the following access level are
currently allowed to do that:\n- Human Resources/Employee\n\t-
Administration/Settings\n\n(Document model: ir.ui.menu)')"
. Below is my code :
Core.py
from openerp.osv import fields, osv
class Student(osv.osv):
_name = "tt.student"
_columns = {
'name': fields.char('Code',size=20,required=True),
'ten': fields.char('Name',size=100,required=True),
'ngay':fields.date('Date',required=True),
}
Student()
main.xml
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<record id="student_tree" model="ir.ui.view">
<field name="name">Student</field>
<field name="model">tt.student</field>
<field name="type">tree</field>
<field name="arch" type="xml">
<tree>
<field string="Mã số" name="name"/>
<field string="Tên" name="ten"/>
<field string="Ngày sinh" name="ngay"/>
</tree>
</field>
</record>
<record id="student_form" model="ir.ui.view">
<field name="name">Student</field>
<field name="model">tt.student</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form>
<group col="2">
<field string="Mã số" name="name"/>
<field string="Tên" name="ten"/>
<field string="Ngày sinh" name="ngay"/>
</group>
</form>
</field>
</record>
<record id="action_student" model="ir.actions.act_window">
<field name="name">Student</field>
<field name="res_model">tt.student</field>
<field name="view_mode">tree,form</field>
</record>
</data>
</openerp>
menu.xml
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<menuitem id="main" name="Student"></menuitem>
<menuitem id="quanly" name="Quản lý" parent="main"></menuitem>
<menuitem id="sinhvien_sub" action="action_student" name="Sinh viên" parent="quanly"/>
</data>
</openerp>
You should add in the security folder the access. Add ir.access.csv file and you should define for each object the access to view, read, write and delete.
I need to create one2one relation in openerp7. I read many articles about this idea and I could to type the following code
problem is : that openerp7 does not send value from parent view (calculation) to child (container)
this my code
testproject.py:
from osv import fields,osv
class container(osv.osv):
_name='container'
_columns={
'calculation_id': fields.many2one('calculation','Calculation'),
'name': fields.char('Name', size=32),
}
container()
class calculation(osv.osv):
_name='calculation'
_columns={
'container_id': fields.many2one('container','Container'),
'namefull': fields.char('Name Full', size=32),
}
calculation()
xml code:
<?xml version="1.0"?>
<openerp>
<data>
<record model="ir.ui.view" id="view_container_form">
<field name="name">container.form</field>
<field name="model">container</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Container">
<field name="name" select="1"/>
<field name="calculation_id" context="{'default_container_id': active_id}" />
</form>
</field>
</record>
<record model="ir.actions.act_window" id="action_container">
<field name="name">Container</field>
<field name="res_model">container</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
</record>
<menuitem name="Container/Container" id="menu_container"/>-->
<menuitem name="Container" id="menu_container_item" parent="menu_container" action="action_container"/>
<record model="ir.ui.view" id="view_calculation_form">
<field name="name">calculation.form</field>
<field name="model">calculation</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Calculation">
<field name="namefull" />
<field name="container_id" />
</form>
</field>
</record>
<record model="ir.actions.act_window" id="action_calculation">
<field name="name">Calculation</field>
<field name="res_model">calculation</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
</record>
<menuitem name="Calculation" id="menu_calculation_item" parent="menu_container" action="action_calculation"/>
</data>
</openerp>
You are correct, OpenERP will not move data around for you -- you will need to modify your Python code to do it.
Oh, and you should name your tables with your model as well -- I'll use a fake model name of my_model:
class calculation(osv.Model):
_name = 'my_model.calculation'
_columns = {
'container_id' fields.many2one('my_model.container', 'Container'),
'namefull': fields.char('Name Full', size=32),
}
def create(self, cr, uid, values, context=None):
new_id = super(calculation, self).create(cr, uid, values, context=context)
self.pool.get('my_model.container').create(cr, uid, {'calculation_id':new_id, 'name':values['namefull'])
return new_id
And something similer to write() in case namefull is updated.
I am using openerp 6.My form contains one text box and I need to get that value and assign it to a variable so to perform calculations and to return a result to store in a new textbox...
I have give .py file here. This will calculate square of the number
from osv import osv
from osv import fields
class test_base(osv.osv):
_name='test.base'
_columns={
'first':fields.integer('Enter Number here'),
'result':fields.integer('Display calclation result'),
}
def first_change(self, cr, uid, ids,first,context=None):
r=first*first
return {'value':{'result':r}}
test_base()
xml file is given here
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record model="ir.ui.view" id="test_base_form">
<field name="name">test.base.form</field>
<field name="model">test.base</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="best Base">
<field name="first" on_change="first_change(first)"/>
<field name="result"/>
</form>
</field>
</record>
<record model="ir.ui.view" id="test_base_tree">
<field name="name">test.base.tree</field>
<field name="model">test.base</field>
<field name="type">tree</field>
<field name="arch" type="xml">
<tree string="Test Base">
<field name="first"/>
<field name="result"/>
</tree>
</field>
</record>
<record model="ir.actions.act_window" id="action_test_seq">
<field name="name">Test Base</field>
<field name="res_model">test.base</field>
<field name="view_type">form</field>
<field name="view_mode">form,tree</field>
</record>
<menuitem id="menu_test_base_main" name="Test Base">
</menuitem>
<menuitem id="menu_test_base_sub" parent="menu_test_base_main" name="Square number" action="action_test_seq">
</menuitem>
</data>
</openerp>