I am trying to update some information on my odoo product with PHP and xmlrpc.
This is my code for update product name.
$models->execute_kw($db, $uid, $password, 'product.product', 'write',
array(array(5), array('name'=>"Newer product 3",'type'=>"consu")));
Now I want to change a "Quantity On Hand" field so I trying this code :
$models->execute_kw($db, $uid, $password, 'product.product', 'write',
array(array(5), array('name'=>"Newer product 3",'type'=>"consu",'qty_available'=>'7')));
but it doesn't work, anyone got any ideas how to fix it?
Thank you.
The field qty_available is readonly.
On odoo10 you can use the following operation, python:
product = models.execute_kw(db, uid, password, 'product.product', 'search', [[('default_code', '=', sku)]])
change_id = models.execute_kw(db, uid, password, 'stock.change.product.qty', 'create', [{
'product_id': product[0],
'location_id': 15,
'new_quantity': 20,
}])
models.execute_kw(db, uid, password, 'stock.change.product.qty', 'change_product_qty', [change_id])
Since the field qty_available is read only there is no way to update it.
To update it you'll need to create a stock move
First make sure that the field qty_available really exists in the model. You can check the fields in the model from (via browser)
settings --> database structure --> models
If not make sure sale, stock, product modules are properly installed. By the way in my odoo repository (i.e odoo 9 stable) I even can't see qty_available field in the model product.product . But I can see it in the openerp v7. Probably this field is either removed or the field is inheriting some other modules e.g sale_stock etc.
Hope this will solve you problem.
Related
I'm new to Odoo and I'm building a python backend which should create products and price lists in Odoo through API calls. Everything went fairly easy until I tried programatically setting a Price List as archived.
From my research I found that the archive setting is directly linked to the 'Active' property of the Price List. Unfortunately, my code isn't working, and the Price List is still active and unarchived.
price_id = models.execute_kw(db, uid, password, 'product.pricelist', 'create', [{
'name': "Test List",
'currency_id': "1",
'active':'False'
}])
UPDATED
I cannot seem to archive a product. The active property is updated to False, but the product still appears in the product list and not in the archived product list.
models.execute_kw(db, uid, password, 'product.product', 'write', [[prod_id], {
'name': "Testing Apple MacBook 111", 'active':False, 'is_product_variant':False
}])
There are two issues:
You have called create method means every time you run API, it will create a new pricelist. - Use write method.
'active': False - see comment by #CZoellner
I'm trying to change the state of a created invoice from 'draft' to 'posted' using the Web APIs (Python) by referring to this documentation : https://www.odoo.com/documentation/13.0/webservices/odoo.html
I'm updating the invoice as follows :
def makeInvoicePosted(invoice_id):
invoice_ids = []
invoice_ids.append(invoice_id)
common = xmlrpc.client.ServerProxy('{}/xmlrpc/2/common'.format(url))
print(common)
uid = common.authenticate(db, username, password, {})
print("makeInvoicePosted : Odoo Admin User Id : ", uid)
models = xmlrpc.client.ServerProxy('{}/xmlrpc/2/object'.format(url))
models.execute_kw(db, uid, password, 'account.move', 'write', [[invoice_id], {'state':"posted"}])
But I'm getting this error : odoo.exceptions.ValidationError: ('Posted journal entry must have an unique sequence number per company.', None)\n'
What could be causing this ? is there something missing in the request?
Thanks in advance!
I recommend to use Odoo's workflow and business logic here by calling post instead of directly writing the state.
models.execute_kw(db, uid, password, 'account.move', 'post', [[invoice_id],])
Why: because there are a lot of checks and also a lot of things done in this method, you could miss or just do wrong (invoices are very complex). You probably will find some mistakes in your calls right before doing the post, because of the checks in it.
We can read and search data from Odoo using XML-RPC like it's explained on:
https://www.odoo.com/documentation/8.0/api_integration.html
But, for "search" all the examples are using juste simple fields, there's no example to filter on relationship fields.
There is my case:
I have a partner(res.partner) who has a related user(res.user) on "user_id" field.
In this example, I try to get the ids of partners related to the user(id = 36) on "user_id" field, but it doesn't work:
ids = models.execute_kw(db, uid, password,
'res.partner', 'search',
[[['user_id', '=', 36]]],
{'limit': 10})
Any ideas ?
Thank you,
I have the following:
shipment_obj = self.pool.get('stock.picking.in').browse(cr, uid, context.get('active_id'))
This returns correct object, I can access properties, but when I access the O2m field "move_lines", it returns None object and cannot iterate.
Do I need special way to access the products for the specific incoming shipment?
This is in existing OpenERP:
'move_lines': fields.one2many('stock.move', 'picking_id', 'Internal Moves', states={'done': [('readonly', True)], 'cancel': [('readonly', True)]}),
'product_id': fields.related('move_lines', 'product_id', type='many2one', relation='product.product', string='Product'),
stock.picking.in , stock.picking.out and stock.picking are actually the same table stock_picking and stock.picking is considered as the base of both stock.picking.in and stock.picking.out. I think this functionality still have some issues and it is solved in openerp v8.So when you need to browse the object, use the stock.picking whether you are browsing for stock.picking.in nor stock.picking.out
when using
shipment_obj = self.pool.get('stock.picking.in').browse(cr, uid, context.get('active_id'))
here you will get a list of browse records, you can access the one2many field move_lines like
for shipment_id in shipment_obj:
move_lines = shipment_id.move_lines
here you will get the move_lines of each records of the list...
Needed to add this which solves the problem:
if context is not None and context.get('active_id'):
it is the way I thought the method was called that didn't need to check context and active_id since there would always be a context and active_id, I was wrong.
I really need to add an additional 'state' value on my Sale Order object. Since version 7.0, the 'sale_stock' module does exactly that already. When you try to do the same thing from your own module, your key,value just gets ignored. Is there any other alternative to achieve this?
As I found out, this seems to be an old time issue from two years ago as explained in this thread. A suggested workaround there was to do something like this:
_inherit = 'sale.order'
def __init__(self, pool, cr):
super(sale_order, self)._columns['state'].selection.append(('keyx', 'valuex'))
I found this approach logical, but it resulted in the following error:
`File "/home/nicolas/Eclipse/OpenERP/7.0/src/openerp/osv/orm.py", line 2958, in _auto_init
self._field_create(cr, context=context)
File "/home/nicolas/Eclipse/OpenERP/7.0/src/openerp/osv/orm.py", line 764, in _field_create
ir_model_fields_obj = self.pool.get('ir.model.fields')
AttributeError: 'sale.order' object has no attribute 'pool'`
Should this bug be reported at launchpad or is it an unintended use? What other possible solutions can you suggest? Thanks in advance.
try this
from openerp.osv import osv, fields
class sale_order(osv.osv):
_inherit = 'sale.order'
selection_list = [];#add your selection list here.
_columns = {
'state': fields.selection(selection_list,'State');#add necessary arguments
}
sale_order()
simply inherit the sale.order model and add your state field as it is which define in existing model , add the external state which you are required to add additionaly
for eg:
class sale_order(osv.osv)
_inherit ='sale.order'
_columns = {
'state': fields.selection([
('draft', 'Quotation'),
('waiting_date', 'Waiting Schedule'),
('manual', 'To Invoice'),
('progress', 'In Progress'),
('shipping_except', 'Shipping Exception'),
('invoice_except', 'Invoice Exception'),
('done', 'Done'),
('cancel', 'Cancelled'),
**('key','value')**,
This above would be your newly added selection value sequence dosen't matter.
], 'Order State', readonly=True, help="Gives the state of the quotation or sales order. \nThe exception state is automatically set when a cancel operation occurs in the invoice validation (Invoice Exception) or in the picking list process (Shipping Exception). \nThe 'Waiting Schedule' state is set when the invoice is confirmed but waiting for the scheduler to run on the order date.", select=True),
}
sale_order()
than abouve key value will be your additional selection field and you can set it any where in the squence as per your requirements.
having the same problem, I had a look at the thread, you noticed.
I guess that the problem comes from the fact that our modules and sale_stock are "in conflict" because they modify the same field ('state') in the sale.order object and are not depending of each other.
One solution is to modify your own module and adding 'sale_stock" in the 'depends' list of openerp.py :
depends : ['sale_stock',...]
You can see an example in this module which had another (key,value) in state field : http://bazaar.launchpad.net/~agaplan/agaplan-addons/7.0/files/head:/sale_double_validation/
Hope it helps