Computed many2many field dependencies in Odoo 10 - odoo

I am trying to create a new field on the sale.order.line model. This field is called x_all_route_ids, and is meant to contain all of the available stock.location.route for an Order Line.
It should look up the product_id.route_ids and product_id.routes_from_categ_ids for the Order Line, and join them together into a single set of Routes.
I am trying to set this field up through the Odoo UI, but getting error related to my "Dependencies".
I have Dependencies defined as:
product_id, product_id.route_ids, product_id.routes_from_categ_ids
I have Compute defined as:
for record in self:
record['x_all_route_ids'] = record.product_id.route_ids
To start I am just trying to get the field to show the same value as product_id.route_ids, but it's not working. When I save, I get the following error:
Error while validating constraint
Unknown field u'product_id' in dependency u'product_id'
Any idea what I'm doing wrong here?

I was able to get this working. I think the issue was just a bug in the UI that came about because I had been trying so many different things. After refreshing the page, the following worked:
Dependency = product_id
Field type = many2many
Compute method:
for record in self:
full = record.product_id.route_ids | record.product_id.route_from_categ_ids
record['x_all_route_ids'] = full.filtered('sale_selectable')

Related

Odoo: how to set default field for many2many field by id?

i want to set default value in many2many field for example:
that field in models.py:
# alarms
alarm_ids = fields.Many2many(
'calendar.alarm', 'calendar_alarm_calendar_event_rel',
string='Reminders', ondelete="restrict",
help="Notifications sent to all attendees to remind of the meeting.")
also it is default values created by system, and i want first variant by default:
i know that i can set it by id, but dont know how.
You can use Command to set X2many field values.
From the documentation:
Via Python, we encourage developers craft new commands via the various functions of this namespace. We also encourage developers to use the command identifier constant names when comparing the 1st element of existing commands.
Example:
from odoo import Command, models, fields
class CalendarEvent(models.Model):
_inherit = 'calendar.event'
alarm_ids = fields.Many2many(default=lambda self: [Command.link(self.env.ref('calendar.alarm_notif_1').id)])
i just watch in postgres, there is no id`s like in xml screenshots, i just take id of a record and find some documentation.
next example works:

Table name is too long odoo 13

I am getting this error after adding a binary filed I remover the filed but getting the same error
Table name 'n_hesaby_subscription_manager_subscription_manager_res_users_rel' is too long
odoo.exceptions.ValidationError: ("Table name 'n_hesaby_subscription_manager_subscription_manager_res_users_rel' is too long", None) - - -
does anyone know what it means, I can't find it
From the look of the table name it's created from a many2many field between n_hesaby_subscription_manager_subscription_manager and res.users when you don't provide a name for the relation table Odoo will generate it for you model_1_name_model_2_name_rel.
So in your many2many definition specify a shorter name
m2m_field_name = fields.Many2many(comodel_name='res.users',
relation='put_nice_table_name_here',
column1='put_nice_and_short_field_name_here_to',
column2='user_id',
string='You field label')
I'm using my phone sorry for my short answer I hope you get the idea, you can check Odoo standard modules you will find planty of examples.
Always specify the name of the relation in your many2many field is a good practice prevent unexpected behavior.

Error: Not found: Dataset my-project-name:domain_public was not found in location US

I need to make a query for a dataset provided by a public project. I created my own project and added their dataset to my project. There is a table named: domain_public. When I make query to this table I get this error:
Query Failed
Error: Not found: Dataset my-project-name:domain_public was not found in location US
Job ID: my-project-name:US.bquijob_xxxx
I am from non-US country. What is the issue and how to fix it please?
EDIT 1:
I change the processing location to asia-northeast1 (I am based in Singapore) but the same error:
Error: Not found: Dataset censys-my-projectname:domain_public was not found in location asia-northeast1
Here is a view of my project and the public project censys-io:
Please advise.
EDIT 2:
The query I used to type is based on censys tutorial is:
#standardsql
SELECT domain, alexa_rank
FROM domain_public.current
WHERE p443.https.tls.cipher_suite = 'some_cipher_suite_goes_here';
When I changed the FROM clause to:
FROM `censys-io.domain_public.current`
And the last line to:
WHERE p443.https.tls.cipher_suite.name = 'some_cipher_suite_goes_here';
It worked. Shall I understand that I should always include the projectname.dataset.table (if I'm using the correct terms) and point the typo the Censys? Or is this special case to this project for some reason?
BigQuery can't find your data
How to fix it
Make sure your FROM location contains 3 parts
A project (e.g. bigquery-public-data)
A database (e.g. hacker_news)
A table (e.g. stories)
Like so
`bigquery-public-data.hacker_news.stories`
*note the backticks
Examples
Wrong
SELECT *
FROM `stories`
Wrong
SELECT *
FROM `hacker_news.stories`
Correct
SELECT *
FROM `bigquery-public-data.hacker_news.stories`
In Web UI - click Show Options button and than select your location for "Processing Location"!
Specify the location in which the query will execute. Queries that run in a specific location may only reference data in that location. For data in US/EU, you may choose Unspecified to run the query in the location where the data resides. For data in other locations, you must specify the query location explicitly.
Update
As it stated above - Queries that run in a specific location may only reference data in that location
Assuming that censys-io.domain_public dataset has its data in US - you need to specify US for Processing Location
The problem turned out to be due to wrong table name in the FROM clause.
The right FROM clause should be:
FROM `censys-io.domain_public.current`
While I was typing:
FROM domain_public.current
So the project name is required in the FROM and `` are required because of - in the project name.
Make sure your FROM location contains 3 parts as #stevec mentioned
A project (e.g. bigquery-public-data)
A database (e.g. hacker_news)
A table (e.g. stories)
But in my case, I was using the LegacySql within the Google script editor, so in that case you need to state that to false, for example:
var projectId = 'xxxxxxx';
var request = {
query: 'select * from project.database.table',
useLegacySql: false
};
var queryResults = BigQuery.Jobs.query(request, projectId);
check exact case [upper or lower] and spelling of table or view name.
copy it from table definition and your problem will be solved.
i was using FPL009_Year_Categorization instead of FPL009_Year_categorization
using c as C and getting the error "not found in location asia-south1"
I copied with exact case and problem is resolved.
On your Big Query console, go to the Data Explorer on the left pane, click the small three dots, then select query option from the list. This step confirms you choose the correct project and dataset. Then you can edit the query on the query pane on the right.
may be dataset name changed in create dataset option. it should be US or default location
enter image description here

Using compute Method for Calculating Values in Odoo Module customization?

My aim is to create a CRM-Lead extension module in Odoo. My modules aim is to add certain more fields to the Lead section in The CRM Odoo module.
I created a module code which is working fine but one problem is that I have a field named percentage in it, which should calculate like
amount * 100 & store in database. So for that I used compute attribute in Model. But its is not calculating the value... I will provide my code below :-
from openerp import models, fields, api
class legacy_sales(models.Model):
_inherit='crm.lead'
legacy_description = fields.Text(string="Comments")
legacy_amount = fields.Float(string="Amount")
legacy_startdate = fields.Date(string="StartDate")
legacy_percentage = fields.Float(compute='_compute_percentage',store=True)
#api.depends('legacy_amount')
def _compute_percentage(self):
self.legacy_percentage = self.legacy_amount * 100
legacy_sales()
Here legacy_percentage is not storing calculated value in database.. please give advice:-
Browse self to set field value:
for record in self:
record.legacy_percentage= record.legacy_amount * 100

OpenERP - how to get form field value in python code

I have a field in the XML file, categ_id. I need to access the value of that field in my Python code, in product_template class. I tried vals as a paremeter but it did not work.
If you can give me an example object.field_name as it relates to the case I have described.
Nebojsa - your question is not understandable at all, but I'll try to answer it. You can get the value of categ_id in two or even three ways:
vals.get('categ_id') - this is the way to go when you are creating a new record or updating existing one with change in categ_id field - otherwise you'll get an error or NoneType defined.
template = self.pool.get('product.template).browse(cr, uid, ids) and then template.categ_id.id - to get the value when you do have an id of the record, so you can ask database of value stored or in transaction, if there were any changes.
third opition is the dirtiest one, because it is just cr.execute("SELECT categ_id FROM product_template WHERE id = %s", (ids[0],)) and then category_id = cr.fetchall() - it is not always good option to use that, as it asks for records already existing in database (not counting these in transaction)