Customise odoo 12 dashboard - forms

I am creating dashboard in that I want show form view. the code for dashboard is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<!-- Action for survey-->
<record model="ir.actions.act_window" id="survey_create_action">
<field name="name">survey.create</field>
<field name="res_model">survey.survey</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="view_id" ref="survey.survey_form"/>
</record>
<!-- board form view -->
<record model="ir.ui.view" id="board_form" >
<field name="name">Surveys</field>
<field name="model">board.board</field>
<field name="arch" type="xml">
<form string="survey_page_questions">
<h1>Survey</h1>
<hpaned>
<child1>
<action string="Survey" name="%(survey_create_action)d"/>
<button type="action" name="%(survey.survey_form)d"/>
</child1>
</hpaned>
</form>
</field>
</record>
<record model="ir.actions.act_window" id="board_action">
<field name="name">survey.action</field>
<field name="res_model">board.board</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="usage">menu</field>
<field name="view_id" ref="board_form"/>
</record>
<menuitem id="survey_menu" name="Survey" />
<menuitem id="survey_menu_form" name="survey" parent="survey_menu" action="board_action"/>
</odoo>
after loading survey menu nothing will display. also I have create button on dashboard after click on button I want display form view but it gives me following error:
File "/usr/local/sampada/survey-workspace/spn/odoo/models.py", line
2780, in read
self._read_from_database(stored, inherited) File "/usr/local/sampada/survey-workspace/spn/odoo/models.py", line 2959,
in _read_from_database
forbidden = missing.exists() File "/usr/local/sampada/survey-workspace/spn/odoo/models.py", line 4319,
in exists
self._cr.execute(query, [tuple(ids)]) File "/usr/local/sampada/survey-workspace/spn/odoo/sql_db.py", line 148, in
wrapper
return f(self, *args, **kwargs) File "/usr/local/sampada/survey-workspace/spn/odoo/sql_db.py", line 225, in
execute
res = self._obj.execute(query, params) psycopg2.ProgrammingError: relation "board_board" does not exist LINE 1: SELECT id FROM
"board_board" WHERE id IN (false)
^
why this is happen? any help is appreciated.thanks

relation "board_board" does not exist
This error means board_board table is not available in the database. Whenever a module is installed, models defined in that particular is installed creates corresponding tables in the database, for board.board model in this case, board_board table must exist. The table not found may be caused by one of the followings:
=> Module not installed properly, install/re-install/upgrade
=> models/__init__.py file doesn't import the xxx.py file that defines the model definition
After the module is imported, check for the Debug => Settings => Technical => Models list and search if your particular model is listed or not.

Related

How to hide column in odoo 12?

Please i need to hide column "Description" in table "Order Lines" in form view external_id="sale.view_order_form", hide this column if details==True
Here is python code:
class ClassSaleOrder(models.Model):
_inherit = 'sale.order'
details = fields.Boolean()
Here is xml file :
<record id="module_sale_order_line_form" model="ir.ui.view">
<field name="name">module.sale.order.line.form</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<xpath expr="//field[#name='partner_id']" position="after">
<field name="details"/>
</xpath>
</field>
</record>
You need to use position='attributes' and define the value for invisible attribute.
<xpath expr="//field[#name='order_line']/form/group/field[#name='name']" position="attributes">
<attribute name="invisible">[('details', '=', True)]</attribute>
</xpath>
Use the below code for making description field invisible when details is true
<xpath expr="//field[#name='order_line']/tree/field[#name='name']" position="attributes">
<attribute name="attrs">{'invisible':[('details', '=', True)]}</attribute>
</xpath>

Error while validating constraint Field `file` does not exist

I have created new model that inherit from product.product, in the python file i have added this function:
class ClassProduct:
_inherit = 'product.product'
field1 = fields.Char()
I try to add new field in model product.product but i got this error while restarting server:
File "/home/omar/odoo/odoo12/odoo/models.py", line 1112, in _validate_fields
raise ValidationError("%s\n\n%s" % (_("Error while validating constraint"), tools.ustr(e)))
odoo.tools.convert.ParseError: "Error while validating constraint
Field `field1` does not exist
Error context:
View `product.template.common.form.costumized`
[view_id: 2073, xml_id: module.product_template_form_view_costumized, model: product.product, parent_id: 388]
None" while parsing /home/omar/odoo/custom-addons/addons12/module/views/views.xml:305, near
<record id="product_template_form_view_costumized" model="ir.ui.view">
<field name="name">product.template.common.form.costumized</field>
<field name="model">product.product</field>
<field name="inherit_id" ref="product.product_normal_form_view"/>
<field name="arch" type="xml">
<xpath expr="//page[#name='inventory']" position="after">
<!-- Add your fields or attributes here -->
<page string="dxf Viewer">
<group>
<group>
<!--<field name="choose_dxf_file" widget="image"/>-->
<!--<field name="name"/>-->
<field name="field1"/>
</group>
</group>
</page>
</xpath>
</field>
</record>
your class should extend from
models.Model
so your class signature will be:
class ClassProduct(models.Model):

how to add field to product.template in odoo 12

I would like to display a field in Form View of the product module, here is the python file (i use odoo 12.):
class ClassProductInherited:
_inherit = 'product.template'
file = fields.Char(string="Choose File")
Here is xml code (i use odoo 12.):
<record id="view_product_form_inherit" model="ir.ui.view">
<field name="name">product.template.common.form.inherit</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_only_form_view"/>
<field name="arch" type="xml">
<xpath expr="//page[#name='inventory']/group" position="before">
<group col="2" colspan="2">
<field name="file"/>
</group>
</xpath>
</field>
</record>
When I restart the server, problem is that I have the following error:
File "/home/odoo/models.py", line 1112, in _validate_fields
raise ValidationError("%s\n\n%s" % (_("Error while validating constraint"), tools.ustr(e)))
odoo.tools.convert.ParseError: "Error while validating constraint
Field `file` does not exist
Error context:
View `product.template.common.form.inherit`
[view_id: 2095, xml_id: module.view_product_form_inherit, model: product.template, parent_id: 402]
None" while parsing /home/omar/odoo/custom-addons/addons12/module/views/views.xml:403, near
<record id="view_product_form_inherit" model="ir.ui.view">
<field name="name">product.template.common.form.inherit</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_only_form_view"/>
<field name="arch" type="xml">
<xpath expr="//page[#name='inventory']/group" position="before">
<group col="2" colspan="2">
<field name="file"/>
</group>
</xpath>
</field>
</record>
1- First, check if the manifest.py file contains:
"depends": [
'product'
],
2- check if the name of your file that contains the class ClassProductInherited: exists in the init.py file like this for example:
from . import my_file
<record id="view_product_form_inherit" model="ir.ui.view">
<field name="name">product.template.common.form.inherit</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_form_view"/>
<field name="arch" type="xml">
<xpath expr="//field[#name='weight']" position="before">
<group>
<field name="file"/>
</group>
</xpath>
</field>
</record>
Try this piece of code and let me know if it works.
check in your .py file that you have to inherit only single module in one ... if you declare more than one module in single record so remove it. and make another record for another module. then after check it you declare or note the field file in your .py file

Editable tree view inside a form view is not saving

I have an editable tree view inside my form view.
See this picture:
I can edit the values inside the tree, but every time I hit the Save button at the top, it doesn't save the updated values inside my tree. It goes back to default (in this case 0).
Below is the code for my form view:
<record model="ir.ui.view" id="score_card_form_view">
<field name="name">Score Card</field>
<field name="model">golf_online_ph.score_card</field>
<field name="arch" type="xml">
<form>
<sheet>
<group string="Score Card">
<field name="round_id" />
<field name="player_id" />
<field name="round_holes">
<tree editable="top" >
<field name="hole_number" readonly="1"/>
<field name="score_value"/>
</tree>
</field>
</group>
</sheet>
</form>
</field>
</record>
What should be my workaround here?
Hello #Adrian Steven Quevada,
Your solved? Else update more info about fields. Because your view seems right.

How to save form data using a custom button in Openerp/Odoo

We have a form with fields. We have added our own "Save" button, and want to persist the data on the form to the server when this button is clicked.
We know how to create actions on the server to handle button clicks, but no idea how to retrieve the form data.
Currently, we are using the inbuilt Save button but need to trigger some extra functionality hence the request.
This is what our XML looks like currently.
<record model="ir.ui.view" id="petra_ticket_hold_dialog">
<field name="name">petra.ticket_request.hold.dialog</field>
<field name="model">petra.ticket_request</field>
<field name="arch" type="xml">
<form string="Hold Ticket" edit="false" create="false" delete="false">
<sheet>
<group colspan="2">
<field name="hold_reason"/>
<field name="status" invisible="1"/>
</group>
<button string="Save" />
</sheet>
</form>
</field>
</record>
Here a small example which can help you. First of all you need to add some action of model to button like this:
<record model="ir.ui.view" id="petra_ticket_hold_dialog">
<field name="name">petra.ticket_request.hold.dialog</field>
<field name="model">petra.ticket_request</field>
<field name="arch" type="xml">
<form string="Hold Ticket" edit="false" create="false" delete="false">
<sheet>
<group colspan="2">
<field name="hold_reason"/>
<field name="status" invisible="1"/>
</group>
<!-- it means that will be calls method 'action_my_action' of object 'petra.ticket_request' -->
<button string="Save" name="action_my_action" type="object"/>
</sheet>
</form>
</field>
</record>
After this you need to add method to your model:
# you can use #api.multi for collection processing like this:
# for ticket in self: ...something do here
# or you can use #api.model for processing only one object
#api.model
def action_my_action(self):
# here you have values from form and context
print(self.hold_reason, self._context)
# todo something here... and close dialog
return {'type': 'ir.actions.act_window_close'}
Restart openerp-server and update your module.
Be careful! Object will be saved in db before your action_my_action.
Hope this helps you.