import user-defined Defaults Odoo - odoo

Today I tried to import some configuration from one data base of Odoo to another (User-defined Defaults) and everything looks ok, but the default values that i'm trying to insert to my new data base (for many2many fields) don't work. I believed it was by for the csv file and i try to add using xml record like this:
<record id="hr_test_record" model="ir.values">
<field name="value_unpickle">2</field>
<field name="name">struct_id</field>
<field name="model">hr.contract</field>
<field name="key">default</field>
<field name="value">I2 .</field>
</record>
but in the database space (for value) appears this way after install the module
value
S'2' +
p0 +
.
And has to look like this
value
I2 +
.
I know this but how can apply this?
I is for Integer
S is for string
V is for value

To store the value as integer, you must use XML notation to encode the \n character (result of pickle.dumps operation) and must not specify a value for the field "value_unpickle".
e.g.
<record id="hr_test_record" model="ir.values">
<field name="name">struct_id</field>
<field name="model">hr.contract</field>
<field name="key">default</field>
<field name="key2"/>
<field name="value">I2
.</field>
</record>
note that you also need to set key2 to empty string if you don't want any conditions/qualifiers for your default value.
(the above is tested in odoo 10)

Related

cannot find out why odoo sequence is incrementing twice?

I created a model with a sequence field on it:
class AimedPurchaseOrder(models.Model):
_name = "aimed.purchase.order"
name = fields.Char('Number', readonly=True, copy=False,
default=lambda self:self.env['ir.sequence'].next_by_code('aimed.purchase.order'))
And I added the sequence like this:
<record id="seq_purchase_order" model="ir.sequence">
<field name="name">Aimed Purchase Order</field>
<field name="code">aimed.purchase.order</field>
<field name="prefix">BCV</field>
<field name="padding">4</field>
<field name="company_id" eval="False"/>
</record>
The problem is that when I open the form view to create a new record, I get the next value of the sequence that it should be saved, but when I save the record it increments another time and I find records in the tree view with this sequence :
BCV0002, BCV0004, BCV0006, ...
How it that possible? How can I fix it so it saves the default value showed at first time without incrementing again?
Update:
When I remove the readonly=True it works fine, but I can't let this field editable.
I'm not fully sure but IIRC you can use force_save="1" since Odoo 11 as attribute on fields in views to tell Odoo to write values for readonly fields.
An example for a readonly field:
<field name="my_readonly_field" readonly="1" force_save="1" />
If on older Odoos (10 and less) there is a community module adding this feature to Odoo which is called web_readonly_bypass and for example can be found here for Odoo 10.

How to reference a planning type in a plan

I have a custom odoo module, which extends some existing modules like hr. I want to create an onboarding plan with several predefined tasks in it.
This is my plan acitivity type xml which works at it should. If I update the applikation with this file, I get the desired tasks in the planning types overview.
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="hr_plan_activity_type_create_work_contract" model="hr.plan.activity.type">
<field name="activity_type_id" ref="mail.mail_activity_data_todo"/>
<field name="responsible">manager</field>
<field name="summary">Create work contract</field>
<field name="note">Create the work contract for the employee.</field>
</record>
<record id="hr_plan_activity_type_employee_model_in_erp" model="hr.plan.activity.type">
<field name="activity_type_id" ref="mail.mail_activity_data_todo"/>
<field name="responsible">manager</field>
<field name="summary">Employee model in ERP</field>
<field name="note">Complete the employee model in ERP (AHV, Banking, etc.)</field>
</record>
</odoo>
This is my plan.xml which should create a plan with the activity types. The creation of the plan works, but if I reference the activity types, I'll get an error message.
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<!-- Onboarding -->
<record id="hr_plan_onboarding" model="hr.plan">
<field name="name">Onboarding</field>
<field name="plan_activity_type_ids"
eval="[(6,0,[ref('mycompany.hr_plan_activity_type_employee_model_in_erp')])]"/>
<field name="plan_activity_type_ids"
eval="[(4,0,[ref('mycompany.hr_plan_activity_type_create_work_contract')])]"/>
</record>
</odoo>
In the manifest.py file I first load the plan.activity.type.xml and then the plan.xml so this shouldn't be a problem.
This is the error message I get when I try to upgrade my customized module mycompany:
File "C:\Program Files (x86)\Odoo 13.0e\server\odoo\addons\base\models\ir_model.py", line 1670, in xmlid_lookup
raise ValueError('External ID not found in the system: %s' % xmlid)
odoo.tools.convert.ParseError: "External ID not found in the system: hr.plan.activity.type.hr_plan_activity_type_create_work_contract" while parsing file:/c:/users/myuser/appdata/local/openerp%20s.a/odoo/addons/13.0/mycompany/data/hr/plan.xml:2, near
<odoo>
<!-- Onboarding -->
<record id="hr_plan_onboarding" model="hr.plan">
<field name="name">Onboarding</field>
<field name="plan_activity_type_ids" ref="hr.plan.activity.type.hr_plan_activity_type_create_work_contract"/>
</record>
Does anyone have any ideas?
String identifier stored in ir.model.data, can be used to refer to a record regardless of its database identifier during data imports or export/import roundtrips.
External identifiers are in the form module.id (e.g. account.invoice_graph). From within a module, the module. prefix can be left out.
Sometimes referred to as xml id or xml_id as XML-based Data Files make extensive use of them.
In your example you used model_name.id which probably does not exist in the database, to reference hr_plan_activity_type_create_work_contract record you just need to replace the model name with the module name.
I can see from the log message that the module name is mycompany, try to replace the model name with mycompany:
<record id="hr_plan_onboarding" model="hr.plan">
<field name="name">Onboarding</field>
<field name="plan_activity_type_ids" ref="mycompany.hr_plan_activity_type_create_work_contract"/>
</record>
Update:plan_activity_type_ids is an x2many field
Use the special commands format to set the x2many field values:
<record id="hr_plan_onboarding" model="hr.plan">
<field name="name">Onboarding</field>
<field name="plan_activity_type_ids" eval="[(6,0,[ref('mycompany.hr_plan_activity_type_create_work_contract')])]"/>
</record>
Edit: Only the first one shows up in the GUI
To replaces all existing records in the set by the ids list (using '(6, 0, ids)') you can provide a list of ids inside the triplet. You can find an example in res_partner_demo.xml inside the base module.
Example:
<field name="plan_activity_type_ids" eval="[(6,0,[ref('mycompany.hr_plan_activity_type_employee_model_in_erp'), ref('mycompany.hr_plan_activity_type_create_work_contract')])]"/>
To add an existing record of id id to the set (using (4, id)) you need to provide one id for each triplet. You can find an example in base_groups.xml inside the base module.
Example:
<field name="plan_activity_type_ids" eval="[(4,ref('mycompany.hr_plan_activity_type_employee_model_in_erp')), (4,ref('mycompany.hr_plan_activity_type_create_work_contract'))]"/>
Your ref ids are wrong. hr.plan.activity.type.hr_plan_activity_type_create_work_contract is wrong. You get only one . in a reference. its [<module_name>.]ext_id_of_object.
If you reference the object from the same module you don't have to use module name.part
If you can see the database tables. then things you are referencing are in table ir_model_data
So if the thing you are referencing is in your own model then you cant use just hr_plan_activity_type_create_work_contract as a reference or your_model_name.hr_plan_activity_type_create_work_contract

odoo 9 how to add relational field to pivot view?

I'm customizing Project's pivot view to show timesheet description along with task's name.
here is my code below but when I click pivot view it shows an error
<!-- Insert Project Issue Pivot Field -->
<record id="project_task_custom_pivot" model="ir.ui.view">
<field name="name">project.task.custom.pivot</field>
<field name="model">project.task</field>
<field name="inherit_id" ref="project.view_project_task_pivot"/>
<field name="arch" type="xml">
<field name="stage_id" position="after">
<field name="name" type="row"/>
<field name="timesheet_ids" type="row"/>
</field>
</field>
</record>
Error below
assert groupby_def and groupby_def._classic_write, "Fields in 'groupby' must be regular database-persisted fields (no function or related fields), or function fields with store=True"
Edit
I re-defined the field "timesheet_ids" as #George Daramouskas mentioned.
timesheet_ids = fields.One2many('account.analytic.line', 'task_id', string="Timesheetss", store=True)
But It didn't work.
So I took a look at the source code in Odoo Source
The function "One2many" has no such a parameter.
I guess the Store=True is for only regular field not related field.
Is there any other solution for this?
Thanks
Create your field with the attribute store=True in the constructor so that the field is stored in the database.

Difference between name and id in an OpenERP form

The code below is a snippet from an OpenERP xml form definition.
<record model="ir.ui.view" id="direct_supplier_invoice_form">
<field name="name">direct_supplier.invoice.form</field>
<field name="model">account.invoice</field>
<field name="type">form</field>
<field name="inherit_id" eval="False" />
<field name="priority">250</field>
<field name="arch" type="xml">
It has two fields that seem very similair:
id="direct_supplier_invoice_form"
<field name="name">direct_supplier.invoice.form</field>
What is the specific purpose of these two fields?
name: is simply the name of the record (field name)
id: is also called xml_id, it's like a name for the records id.
Why is there a name for an id? So you can reference to that id by name instead of numbers (which can vary from installation to installation).
Where are these names saved in db? Just look into table ir_model_data.
I bet you've already used these id-names for references :-)
that's an XML code...
Name refers to the name of the field or record
while ID refers to its reference name so that whenever you are going to access the particular record or field you will have to use its ID.

set other account in accounting module

I am trying to set default account for some fields for that i write some code like
<!-- 1.Income account–311000 -->
<record forcecreate="True" id="property_account_income_product" model="ir.property">
<field name="name">property_account_income</field>
<field name="fields_id" search="[('model','=','product.template'),('name','=','property_account_income')]"/>
<field eval="'account.account,'+str(account_account_456)" name="value"/>
<field name="company_id" ref="base.main_company"/>
</record>
in account.account.template i write code like
<record model="account.account.template" id="account_account_456">
<field name="name">INCOME FROM SALES</field>
<field name="code">311000</field>
<field name="type">other</field>
<field name="user_type" ref="account.data_account_type_income"/>
<field name="reconcile" eval="False"/>
<field name="parent_id" ref="account_account_256"/>
</record>
but after update database it sets different account
i don't know why but correct account are not set
pleas help me
thanks...
Now i got exact Problem Firstly i put record in account.account.template this record is also automatically added into account.account and when i am trying to add record into ir.property search that Account into account.account.template take id and display record from account.account
so the problem is id mismatch in account.account and account.account.template
how to resolve this problem and sorry for English
This is because you must having multiple entries in model="ir.property" for field property_account_income_product for your company so when you try an see the values for the a/c you will find the first value get set on field as your record may be second in list, so it get not selected.