New State in Openerp7 - openerp-7

... In openerp7
I want my new state to show up in sale module ... But it is not appearing
Pls have a look at code below
In sale.py module I added state like:
class Sale_order(osv.Model):
_inherit = 'sale.order'
_columns = {
'state': fields.selection([
('draft', 'Draft Quotation'),
('my_new_state', 'My New State'),
('sent', 'Quotation Sent'),
('cancel', 'Cancelled'),
('waiting_date', 'Waiting Schedule'),
('progress', 'Sales Order'),
('manual', 'Sale to Invoice'),
('invoice_except', 'Invoice Exception'),
('done', 'Done'),
], 'Status', readonly=True, track_visibility='onchange',
help="Gives the status of the quotation or sales order. \nThe exception status is automatically set when a cancel operation occurs in the processing of a document linked to the sales order. \nThe 'Waiting Schedule' status is set when the invoice is confirmed but waiting for the scheduler to run on the order date.", select=True),
}
And in sale_view.xml, I added this piece of code..
<openerp>
<data>
<!-- Inherit the sale order model's form view and customize -->
<record id="sale_form_view" model="ir.ui.view">
<field name="name">sale.order.form.inherit</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<!-- Statusbar widget should also contain the new status -->
<field name="state" position="replace">
<field name="state" widget="statusbar" statusbar_visible="draft,my_new_state,sent,invoiced,done" statusbar_colors='{"invoice_except":"red","waiting_date":"blue"}'/>
</field>
</field>
</record>
</data>
But.... My new state is not appearing between draft quotation and quotation sent
Please guide
Why is this so
Thanks

First thing I would check is to make sure you are replacing the proper field in your view (if there are several instances of a field named "state" in the view you inherit, the wrong occurence could be replaced). Check the view by opening the 'Modify FormView' item in the developper tools/view.
If it is the wrong occurence you are replacing, you main need to change your view definition by using an xpath expression.
Second thing I would check, is make sure the sequence of your inherited view is smaller that the original view you are trying to replace/modify. You can check in 'Manage Views' item in the developper tools/view.
Third thing I would try is to rename your class from 'Sale_order' to 'sale_order' just to match the name of the original class your are trying to override.
Hope this helps.

Related

Odoo write to field not part of the current view

I want to update the field done_date which is part of the project.task form view when pulling a Kanban tile on the stage that is indicated as being the final stage.
My code below works fine if the field is part of the Kanban view but fails to write if the field is only part of the task form view and not part of the Kanban project view.
The done_date field should be written even without being part of the Kanban view.
models.py
# -*- coding: utf-8 -*-
from odoo import models, fields, api
class project_set_end_date(models.Model):
inherit = 'project.task.type'
last_stage = fields.Boolean(string="Final stage")
class project_set_end_date(models.Model):
_inherit = 'project.task'
#api.onchange('stage_id')
def _set_end_date(self):
if self.stage_id.last_stage:
self.date_finished = fields.Datetime.now()
views.py
<odoo>
<data>
<!-- explicit list view definition -->
<record model="ir.ui.view" id="project_set_end_date">
<field name="name">project.task.type.form</field>
<field name="model">project.task.type</field>
<field name="inherit_id" ref="project.task_type_edit"/>
<field name="arch" type="xml">
<xpath expr="//field[#name='fold']" position='after'>
<field name="last_stage"/>
</xpath>
</field>
</record>
</data>
</odoo>
Odoo doesn't write to a field that doesn't exist in the current view. So I suggest adding the field but with the attribute invisible = True to avoid showing it:
<field name="your_field" invisible="True"/>

odoo server error after click on save button

When click on save button gives me odoo server error shown in screenshot
and at backed following error display.
2019-12-14 12:36:25,426 4067 ERROR work_span odoo.sql_db: bad query:
INSERT INTO "survey_page" ("id", "create_uid", "create_date",
"write_uid", "write_date", "create_id_survey", "sequence", "title")
VALUES (nextval('survey_page_id_seq'), 1, (now() at time zone 'UTC'),
1, (now() at time zone 'UTC'), 1, 10, 'test1') RETURNING id ERROR:
null value in column "survey_id" violates not-null constraint DETAIL:
Failing row contains (5, 1, test1, null, 10, null, 1, 2019-12-14
12:36:25.421912, 1, 2019-12-14 12:36:25.421912).
UPDATE
Description: I am trying to display survey title, survey page, survey question in one form for that I have create my custom model. Custom model inherit survey.survey,survey.page,survey.question and also contain two one2many field.
Following is my code:
py file
class SurveyCreate(models.Model):
_name = 'create.survey'
_inherit = ['survey.survey','survey.page','survey.question']
pages_id = fields.One2many('survey.page','create_id_survey','Pages')
questions_survey = fields.One2many('survey.question','create_id_survey','Questions')
survey_id = fields.Many2one('survey.survey', string='Survey',required=False)
page_id = fields.Many2one('survey.page', string='Survey page', required=False)
Xml file
<sheet>
<group>
<field name="title"/>
</group>
<group>
<field name="pages_id" mode="tree">
<tree editable="bottom">
<control>
<create string="Add page"/>
</control>
<field name="title"/>
<field name="questions_id" widget="many2many_tags" context="{'tree_view_ref':'survey_inherit.survey_create_form','default_page_id':active_id}"/>
</tree>
</field>
</group>
<group>
<field name="questions_survey" mode='tree'>
<tree name="questions_tree" editable="bottom">
<control>
<create string="Add Question"/>
</control>
<field name="question"/>
<field name="type"/>
</tree>
</field>
</group>
<group>
<group>
<field name="question"/>
</group>
<group>
<field name="type"/>
</group>
</group>
</sheet>
</form>
as per #Atul suggestion make changes but same error occur
Following screenshot for 1.Form View 2.Error after click on save button
It seems you have created a custom survey action model. and trying to use survey.page as one2many or many2many field on it.
when you add the page and try to save the record it is preventing because in default survey module survey_id field is mandatory. you can have two options to resolve this issue.
inherit the survey.page and Overwrite the field and make it non-required.
survey_id = fields.Many2one('survey.survey', string='Survey', required=False)
Populate the value of survey_id by default (you can use ir.config_parameter)
hope this helps!
Edit: 19th December 2019
You do not need to inherit the create.survey from any model if you do not required to change anything on the default survey mode.
class SurveyCreate(models.Model):
_name = 'create.survey'
_inherit = ['survey.survey','survey.page','survey.question']
Remove the below line from your class.
_inherit = ['survey.survey','survey.page','survey.question']
Instead create a new class for survey.page and overwrite the field like
class SurveyPage(models.Model):
_name = 'survey.page'
survey_id = fields.Many2one('survey.survey', string='Survey', required=False)
Looks like you've created a menu/action for a model which is only used in One2many fields, so the form view of that model is not showing the relation's inverse field (survey_id). In One2many fields there is no need to show this field, because Odoo is doing some black magic for them.
So the best way IMO is to create your own form view for that model. You also have to specify this form view as default on your menu action.

What is the right odoo 8 XML syntax for view_ids field

I am trying to customize the crm lead object. Class is defined this way
class yvleads(models.Model):
_inherit = 'crm.lead'
_name = 'crm.lead'
Now I added a menu item to display the added elements for which I have both a tree view and a form view. I have added a lett menu item referening a ir.actions.act_window. When this action is defined as
<record model="ir.actions.act_window" id="yvleads_mgt">
<field name="name">Leads Yves</field>
<field name="res_model">crm.lead</field>
<field name="view_type">form</field>
<field name="view_mode">form,tree</field>
<field name="view_id" ref="tree_view_yves_leads"/>
</record>
this works fine for the list-tree view but when I click on any item or the create button, I get the default form view for crm.
To add my customized view for form also, my understanding of odoo documentation is that I should use view_ids element but I was not able to get it right
I have tried several syntaxes with/without brackets, using eval="" or inside the xml definition but with no success. Searching this forum for string name="view_ids" was not very helfull, may be it is not the best practice to do that? any help appreciated
<record model="ir.actions.act_window" id="yvleads_mgt">
<field name="name">Leads Yves</field>
<field name="res_model">crm.lead</field>
<field name="view_type">form</field>
<field name="view_mode">form,tree</field>
<field name="view_ids">(tree,tree_view_yves_leads),(form,form_view_yves_leads)</field>
</record>
this is the right syntax :
<field name="view_ids"
eval="
[
(5, 0, 0),
(0, 0, {'view_mode': 'tree', 'view_id': ref('tree_external_id')}),
(0, 0, {'view_mode': 'form', 'view_id': ref('form_external_id')}),
]"
/>
The view_id you used in your action is valid only when you click on the menu connected to that action.
What you need to use is view inheritance, i.e. you need to redefine the existing views:
<record id="new_view" model="ir.ui.view">
<field name="name">new view</field>
<field name="model">crm.lead</field>
<field name="inherit_id" ref="crm_lead.existing_view_id"/>
<field name="arch" type="xml">
<data>
...
</data>
</field>
</record>
inside the data tag you can accomplish the modifications you need following the instructions in the provided link.
In theory you could also change the whole view, but this could ba problematic if other modules inherits that same view.
This way every time you open crm.lead model in any way, your view is used.
Btw the correct syntax for view_ids would be:
<field name="view_ids" eval="[(6, False, [ref('view_id_1'), ref('view_id_2')])]">
I think very useful for this link so please check it.
https://www.odoo.com/forum/help-1/question/for-which-reason-can-i-add-a-value-to-view-ids-of-a-window-action-97682

Odoo header buttons missing

I'm having a problem with the create button appearing in tree view. Neither does the next or previous buttons appear in the form view. However, the data is being retrieved from the database.
Tree form with missing buttons
The module I'm trying to make is an extended module of the human resource module, like the included HR attendance module. The extended module doesn't inherit anything and security hasn't been added yet. Only a menu item is added to the main module.
A module I previously created by inheriting the main HR module created the buttons as expected.
Expected outcome(different module)
training.py:
from openerp import fields, models, api
class ew_training(models.Model):
_name = 'hr.training'
var = fields.Char( string='variable')
training_view.xml:
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<!-- Main Submenu -->
<menuitem id="menu_training_tree" action="action_view_training"
parent="hr.menu_hr_main" sequence="6"/>
<record id="action_view_training" model="ir.actions.act_window">
<field name="name">Training</field>
<field name="res_model">hr.training</field>
<field name="view_type">tree</field>
<field name="view_mode">tree,form</field>
</record>
<record id="view_training_tree" model="ir.ui.view">
<field name="name">hr.training.tree</field>
<field name="model">hr.training</field>
<field name="arch" type="xml">
<tree>
<field name="var"/>
</tree>
</field>
</record>
<record id="view_training_form" model="ir.ui.view">
...
</record>
</data>
</openerp>
Please try avoid using the old API
EDIT
This should be work if you are trying to call differents views in differents actions.
The problem is not the button create, the problem is that you are not calling the tree view on your action action_view_training, try adding this line after view_mode:
<field name="view_id" ref="view_training_tree"/>
EDIT
To solve your case you only need to change in the view_type, you should use form:
<record id="action_view_training" model="ir.actions.act_window">
<field name="name">Training</field>
<field name="res_model">hr.training</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
</record>
It should be work perfectly!!! I hope this could be helpful for you.
Just for Information.
in action view_type tree can be used when you want to create hierarchical view, It will not give you ability to create or update record. view of company structure in Odoo is the example of view type tree.
and view_type to form in action will allow you to create normal tree, form view with ability to Create, Update, Duplicate, Delete.
Hope this helps.

OpenERP default value for many2one relationship

Lets assume the following model
class visit(osv.Model):
_name = "visit"
_order = "date desc"
_rec_name = "date"
_columns = {
'date': fields.datetime('Date/Time', required=True),
'res_partner_id': fields.many2one('res.partner', 'Client', required=True),
}
And we have the following view:
<record id="visit_form_view" model="ir.ui.view">
<field name="name">visit.form.view</field>
<field name="view_type">form</field>
<field name="model">visit</field>
<field name="arch" type="xml">
<form string="Visit">
<field name="date" />
<field name="res_partner_id" />
</form>
</field>
</record>
I have extended the res.partner to display a list of visits within a notebook page. When I Add an Item to the visits page within the customer, how do I set the default value of the res_partner_id combobox to the current customer?
After reading your question and comment, I would suggest you to use one2many relation between two objects and keep one2many list view inside partner, from where one can create the record , does not need to select the partner and record is created only for that partner.
Cheers,
Parthiv
Google OpenERP _defaults (a dictionary) and default_get (a method).