Odoo Warning - Missing Record Record does not exist or has been deleted . While creating new customer - odoo-9

Here is the screenshot of the warning which is apperaing while creating customers
I am not able to create new customers in odoo.
Initially I have done some customization in my module ...after that customization my code worked absolutely right, I have created new customers also..but after I dont know why i am not able to create new customers...
please suggest me some solution.
Thank you

I've had a similar problem related to a customized module in Odoo 10. I did some pretty thorough research and the Odoo ORM is doing some things it probably shouldn't be and that I'm not smart enough to sort out.
The sections in the Odoo 10 ORM API Documentation about creating models and fields were kind of helpful, but the documentation on the ORM is severely lacking and in some cases incorrect.
I eventually fixed it by doing the insert manually with the self.env.cr psycopg2 cursor available in the model's custom methods.
That would look something like the
from odoo import models
class your_class(models.Model):
def custom_create_method(self):
self.env.cr.execute("""
INSERT INTO customer_model_name
(name, value, other_value)
VALUES
('{}', '{}', '{}')
RETURNING id;
""")
new_id = self.env.cr.fetchone()
This has the disadvantage of introducing the possibility of an SQL injection attack into your code, so you'll need to be careful of that.
This is definitely not the ideal solution, but it does work. I believe the problem to be related to the Odoo ORM's handling of computed fields, but that is just a not-really-all-that-educated guess at what's going on.
Hope this helps.

For some reason we found a pattern where we had to comment out one of the dependancies, reinstall/update the module in question, then put it back in. In this case it was res in the custom module's __manifest__.py
i.e.:
'depends': ['base', 'res', 'sale_management', 'account', 'account_payment'],
#'depends': ['base', 'sale_management', 'account', 'account_payment'],
Becomes:
#'depends': ['base', 'res', 'sale_management', 'account', 'account_payment'],
'depends': ['base', 'sale_management', 'account', 'account_payment'],
Then install, see if the error goes away, then shut down the server and flip the comment again

Related

How to set up raw_id_fields in django-rest-framework?

In Django admin, one can set up a raw_id_fields in order to have a search widget instead of a select box. This is very neat to spare up a lot of database queries when the foreign key table is huge.
What is the equivalent in the Django Rest Framework browsable views?
Django Rest Framework 3 no longer supports widget attribute on serializer field. But to get your browsable API even usable, try changing style attribute to use 'base_template': 'input.html' as in following example:
class CustomerAddressSerializer(serializers.ModelSerializer):
customer = serializers.IntegerField(source='customer_id' style={'base_template': 'input.html', 'placeholder': "Customer ID"})
class Meta:
model = models.CustomerAddress
fields = ('id', 'customer', 'street', 'zip', 'city')
This way your huge select tag with thousands foreign key options will change to simple text input. For more info check docs at http://www.django-rest-framework.org/topics/browsable-api/#handling-choicefield-with-large-numbers-of-items
There's nothing to support this currently. I'm pretty sure that pull requests would be welcomed.
Seconding what Carlton says, although it'd be worth discussing in a ticket prior to taking a stab at the implementation.
Alternatively, you might want to take a look at using an autocomplete widget...
http://www.django-rest-framework.org/topics/browsable-api/#autocomplete

How to massive delete in php-activerecord where id NOT in list?

I'm running a CodeIgniter application with PHP-Activerecord installed and I need to do a massive delete. The PHP-AR library supports massive update and delete, but the function only takes the ids that you want to delete/update. I'm trying to do a massive delete where the ids are NOT in the list.
delete from table where id not in (1,2,3...,500)
Unfortunately, the PHP-Activerecord website is of no help, and their forums are so horribly built (no search... seriously?) that I'm truly stuck.
edit: Please note, CodeIgniter's built-in ORM is not the same as PHP-Activerecord. Just thought I'd clarify that.
A bit late but this may help someone else. In PHPActiveRecord, do it in this way:
$ids_to_delete = array(1,2,3);
YourModel::delete_all(array('conditions' => array('id NOT IN (?)', $ids_to_delete)));
Ref: http://www.phpactiverecord.org/docs/ActiveRecord/Model#methoddelete_all
SInce active record is actually build string query with function, you can use this method:
- make your list as string
- make this query : $this->db->where('id not in',$string)->delete('table')

cakephp 2.1 view associated data across all add.ctp, edit.ctp, view.ctp

I have an "examinations" table, its consultation_id relates to "consulsations" table, which in turn its consulation_id relates to the "patients" table.
Now, when I am in the add.ctp, edit.ctp or view.ctp of the "Examinations" Views I need to pull the "patients" details in so that some patient info can appear as to who the form pertains to as patient.
I have tried joins. Not to say they dont work. I am new to cakephp and I really need help as to how it will appear within the controller and how the view.ctp will display it.
I thought of elements but they are just .ctp files right?
Please if anyone can help regarding this it would be so appreciated. I've been trying to do this now for a week and I know there is something simple I am dont doing or thinking rights about.
So you just want to pull in related data? Pretty simple.
In your ExaminationsController methods.
$patients = $this->Examination->Consultation->Patient->find('all',
array('conditions'=>array('consultation_id'=>$id,'examination_id'=>$e_id)));
Something similar to this, not quite sure on which id you need to pass, as it will depend on how your models are linked up. http://book.cakephp.org/2.0/en/models/retrieving-your-data.html
However, if your models are linked up properly, you should get this data anyway. If not set your models recursion to be higher.
$this->Model->recursive = 2;

Sorting a view by dropdown

Hey, i've been looking around for a ajax dropdown sorter for my Views in Drupal.
Unfortunatly, i haven't found alot of usefull information about this subject.
Can anyone tell me if theres a solution already available or can help me started on a custom module by telling me which hooks i should use?
I had a similar issue. Unfortunately I wasn't able to sort the data from the database which is by far the best way. I was however able to take the data and sort it with PHP using a preprocessor function. Depending on the name of your view, setup a function similar to the following:
function templatename_preprocess_name_of__view(&$vars)
{
//Super sweet sorting code goes here
}
The name of your view needs to follow the name of the template file that it is driven by, if there isn't on you should create one. Make sure to change dashes to underscores in your function name. Hope this is helpful. If you find a way to do it from the DB I'm all ears because that would be super awesome.

how to add more simple products into configurable products using magento API

How can I simply add new simple products incrementally to configurable products?
or do I still need to retrieve the 2 original arrays of the pre-defined configurable product (getConfigurableAttributesData and getConfigurableProductsData) first, append the new arrays and set them again? Is it worked for my case just as the first-time creation?
And if the new simple product owns a new attribute / attribute options, do I also need to create /edit the attribute first before adding?
Thanks in advance!
The API as it stands does not have the functionality to do this.
Your options are:
Extend the API. (Hours of fun)
Do it with Magento methods in your own module or standalone code that includes Mage.php.
SQL script mixed in with your existing API code.
Buy someone's module - (Hope your German is good)
The approach you take also depends on your SKU naming scheme, if you have a simple BASECODE-SIZE-COLOUR type of scheme then the SQL option can work a treat, and in next to no time, but will be heavily scorned on by Magento evangelists.
That means you are probably going to have to write your own code. Here is a very useful site that should help get you started:
http://www.ayasoftware.com/
As well as being able to import configurables (by a variety of means including SQL) there are also snippets of code useful for updating superattribute price differentials. No readymade complete solution, but, you may need to roll your own anyway depending on your SKU naming scheme.
Whilst you are at it you may also want to write some code to find simple products that are not hooked up to anything when they should be, i,e. the ones with no visibility.

Resources