Adding new field on Odoo Product Variant - odoo

I am trying to add new field to product.product model.
What I've done so far is:
Add new field on the following model (From Settings > Database Structure > Models):
product.product
with the following details:
Name: x_product_cost
Field Label: Product Cost
Field Type: Float
and leave the rest to default.
The problem is i am unable to show it on the form. This is the only code that is generated when I tried to edit Form:
View Name: product.product.form
Object: product.product
Inherited View: product.template.common.form
Product Variant
lst_price
I can't use product.template model, since that inherits to product.product
Am i missing something here?
PS: I am trying to temporarily fixed assign-different-cost-on-product-variant bug as specified here
https://github.com/odoo/odoo/issues/1198
Can anyone help me with this?

Actually instead of modifying the model from the Odoo configuration, you should create a custom module, in which you will add the new fields and the new behaviors that you need.
To do so you will have to inherit from the models in the python files to extend them, and you will surely have to modify the views as well, so that your custom fields get displayed.
For reference on how to extend models, create a custom module and create the views, you should refer to the Odoo documentation that you can find here.
As an additional note in case you didn't know, but their is a new API that appeared in the version 8 of Odoo, if you can use it, it is much easier and much nicer.

Related

Modifying Domain of Many2One using Many2Many

Just to preface, I'm using Odoo 10 Enterprise.
I have a custom module with the following (these are just the relevant fields) on its form:
orange_tag_id = This is a Many2Many field with the _Checkboxes widget defined that's connected to a Tags module (we'll just call it orange.tags). This field displays six or seven tags I've created and then applied to various products within the 'product.product/template' module.
orange_child_ids = This is just a One2Many within a child module of the parent module. This lists a product_tmpl_id Many2One and then a read-only copy of orange_tag_id from the parent that just copies whatever is selected in orange_tag_id in the parent form (this was created just in case defining parent.orange_tag_id in the domain didn't work).
When a tag is selected from the orange_tag_id checkbox, it should sort of modify the domain of product_tmpl_id in orange_child_ids and then only display the products in the drop-down display that have been tagged with the selected active tag. I've managed to get this sort of working by just adding the following to the form XML view within orange_child_ids:
<field name="product_tmpl_id" domain="[('orange_tag_id.id','in',parent.orange_tag_id[0])]"/>
This will display only the products that have been tagged with the selected tag with one exception: Tag6's products (just calling it this because its ID was 6) will always display in the drop-down regardless of whether it's selected or not. If Tag2 is selected, then Tag2 and Tag6's products will display. I tried removing Tag6 from any products that had it defined, then deleting the Tag6 record, re-creating the tag, and re-applying it to the relevant products, but the issue persists. I also can only select one tag in the checkbox -- if more than one is selected, I get the following error from product_tmpl_id:
TypeError: not all arguments converted during string formatting
This isn't as big of a deal as not having the correct records displaying, but I'd also like to resolve this, but I'm not entirely sure how.
I've searched for hours and am aware of methods where this can be done in self-hosted installations, however, we're using Odoo 10 Enterprise (I've omitted the required x_ in my aforementioned custom fields just for easier readability), and I have no access to the file system and consequently can't make modifications where that's required. I've been trying to figure this out using just the Developer Tools and my administrative access to the database's settings.
I've messed around a lot with the domain, looked through many questions and forum threads, and what I have was the only thing that worked. Is there any way to get this working correctly within the limitations of Enterprise?
Much obliged.
It appears that adding [2] after the [0] makes everything work and resolves the two issues I was having, so:
<field name="product_tmpl_id" domain="[('orange_tag_id.id','in',parent.orange_tag_id[0][2])]"/>
This will filter the results of the Many2One based on the records selected in the Many2Many field.
While [('orange_tag_id.id','in',parent.orange_tag_id[0][2])] will work, it is extremely obscure.
I advise you to go with [('orange_tag_id.id','in',parent.orange_tag_id.ids)]

Inherit purchase order and create new object

Blockquote
I inherit the _inherit='purchase.order, and create new object with name _name='job.order' and use its view but when i am going to save it showing error (odoo warning) in pic.
use _inherits instead of _inherit this way you will create new object with with all field of 'purchase.order plus new field you declare in your model that won't affect original model.
for reference check res.user model in base module

Prestashop 1.6 custom module how to add custom input and table in Configuration at Back Office

I am trying to create a custom footer module for my site, It is my first time to create a module in prestashop 1.6 and I read about this article
http://doc.prestashop.com/display/PS16/Adding+a+configuration+page
my problem is i cannot fully understand if I need to create a custom table for my module or not
Configuration::updateValue('FOOTERCUSTOM_NAME', $footercustom);
as you can see in this code, the Configuration table is already created and Configuration::updateValue is a default prestashop code
if I wanted to create a input 1 , input 2 and input 3 at our configuration page in module backoffice and it automatically output the data in the database at my hookfooter.
what is the proper way of doing this?
Note that I already succeeded in creating a basic module, my main problem in how to insert data on my database using the configuration in my module
You don't have to a create a custom table. With the Configuration::updateValue method you can store/update values in the ps_configuration table and you can retrieve these values with the Configuration::get and Configuration::getMultiple methods. Values can be removed with the Configuration::deleteByName method.
Example:
Configuration::updateValue('FOOTERCUSTOM_INPUT_1', $input1Stored);
$input1Retrieved = Configuration::get('FOOTERCUSTOM_INPUT_1');
You can refer to this guide as well, still valid
http://doc.prestashop.com/display/PS15/Creating+a+PrestaShop+module#CreatingaPrestaShopmodule-ThegetContent()method

How use a fields of module A in module B

i have two module opportunities and job positions .
i am trying to use only one field of "job positions" name Employees in "opportunities" module.
i am new in openerp and have no knowledge about python . so i am using developer option of openerp . i am attaching my both module file .
Is there any attribute of fields or other so my field will use the value of other module values like as :-
crm.lead xml file:-
<field name="name" module="hr.job" />
here module is not using value of "hr.job" and using of "crm.lead" value.
if i used other name it give me "not field found" error.
please expert help me
You seem pretty confused. What you've attached are view files for your modules, for instance one of them is the form view for object named hr.job. This is not as you call it "module files".
What you need to do is create a many2one (or many2many) field from the referenced object you want to the target object you need, meaning adding a field to whatever class's columns you need in the corresponding py file and not view. A very simple example for a class named opportunity_opportunity:
class opportunity_opportunity (osv.osv):
_name = "opportunity.opportunity"
_columns = {
'name' : fields.char('Name', size=64),
'employee_id': fields.many2one('job.position','name')
}
opportunity_opportunity()
you can later add it in the opportunity_view.xml file as any other field:
<field name="employee_id" string="Employee"/>
More importantly, I think you need to seriously first read and understand the developer book: OpenERP 6.1 Developer Book
EDIT: I just noticed you had already posted the same question yesterday here link, this is very frowned upon in stackoverflow. Please take your time to read the openerp documentation before posting questions.

Modifying one of OpenERP's core fields using a custom module

Sometimes our OpenERP users want to make a small change to a field in a core OpenERP module. For example, they want the product screen's Rack, Row, and Case fields to be longer than 16 characters.
Can I change an existing field without making changes to the module that declared it? I'd rather make the changes using our own custom module, instead of editing the product module itself.
I've got this working, but I'm hoping that someone else knows a cleaner way.
You can inherit the core module's class in your custom module, and then just declare a new field with the same name as the one you want to change. Essentially, just copy the field declaration from the core module, paste it into your custom module, and then make the changes you want. For example, our product_notes module widened the Rack, Row, and Case fields to 255 from the product module's 16.
_columns = {'loc_rack': fields.char('Rack', size=255),
'loc_row': fields.char('Row', size=255),
'loc_case': fields.char('Case', size=255)}
The reason I don't like this is that you now have duplication for all the other attributes of the field. If you change the field length, and then the core module changes the help text, you will still have the old help text. I was hoping that there would be some way when the modules are loading to go in and adjust the field attributes of your parent, but I couldn't find any hooks at the right time.
One change that you can make more easily is the default value of a field. Just declare a default value for a core module's field in your custom module, and it will replace the original default. For example, we changed the defaults for sale_delay and produce_delay from those in the product module.
_defaults = {'sale_delay': lambda *a: 5,
'produce_delay': lambda *a: 0}
In ODOO we can change any attribute of a field using xml.
<field name="loc_rack" position="attributes">
<attribute name="string">Axis</attribute>
</field>
But some case like extending the size of a field its failed.
You need to inherit the product form.
Here you go.
from openerp.osv import fields, osv
class product_product(osv.Model) # <<<v7
_inherit = 'product.product'
_columns = {
'loc_rack': fields.char('Rack', size=<your size>),
'loc_row': fields.char('Row', size=<your size>),
'loc_case': fields.char('Case', size=<your size>)
}
In simple words you just need to override the field and apply your attribute changes it will reflect.