Generate a code with a wizard on openERP 7 - module

i'm new to openERP and I hadn't found an exhaustive and simple guide for wizards.
I have to do a wizard that generates a code by using the product_id.
This wizard have to generate the code of all the products when i click on it and put it in in the field EAN13. I have no idea how to create the wizard that take the code, generates his own code and put it in the field.
Sorry for my bad english :(

You can check OpenERP Technical Memento

You need to create a new memory model
class ean13_wiz(osv.osv_memory):
_name = 'ean13.wiz'
_description = 'EAN13 wizard'
_columns = {
'ean_template':fields.char('ean_template', size=13, required=True),
}
_defaults = {
'ean_template': '2100000000000',
}
def ean13_logic(self, cr, uid, ids, context=None):
# your duplicate buziness logic
...
I added only 1 field for init the ean13 template
When you click on the submit button you should add the view xml action to your ean13_logic to add a ean to every product. maybe have some feedback how many are changed.
look at the link for more info: wizard example

Related

Batch create based on user selection in Odoo

I have the following models Program, Course, ProgramAdmission, CourseEnrollment.
Each course is associated with a program.
During program admission, I am showing the list of available courses for the selected program. For each shown course, I want to show a dropdown menu with the following selections: Not Planned and Planned.
Now if the user saves the new program admission, I want also to enroll the user in the planned courses by creating CourseEnrollment in the server-side for each planned course.
And if the user discards the new program admission, nothing should be created in the database.
How can I allow for such conditional batch creation of model objects?
Thank you!
It's easy, you just need to start to coding it. Create the module with the models relations and fields. On the ProgramAdmission model add a Many2one field to the Program model and another to the Course model. If you cancel the form while creating a new record nothing will be saved in your DB, but if you hit the Save button it will call the create method for new records and write methods for existing ones. Override the create method to be able to dynamically create a new record of the CourseEnrollment model and associate it with the ProgramAdmission record to be created by saving it to a new Many2one field in the same ProgramAdmission model.
To make what I mean more clear:
from odoo import models, fields, api
class Program(models.Model):
_name = 'school.program'
name = fields.Char()
class Course(models.Model):
_name = 'school.course'
name = fields.Char()
class ProgramAdmission(models.Model):
_name = 'school.program.admission'
course_id = fields.Many2one('school.course')
program_id = fields.Many2one('school.program')
enrollment_id = fields.Many2one('school.course.enrollment')
#api.model
def create(self, vals):
enrollment_id = self.env['school.course.enrollment'].create({
'course_id': vals['course_id'],
'program_id': vals['program_id']
})
vals['enrollment_id'] = enrollment_id.id
return super(ProgramAdmission, self).create(vals)
class CourseEnrollment(models.Model):
_name = 'school.course.enrollment'
course_id = fields.Many2one('school.course')
program_id = fields.Many2one('school.program')

How to show default partner_id in wizard which is selected in sale order form but not saved yet?

I selected the customer name in the sales order form. And above the sale order line, I added a button, for this button wizard is opened and getting information from the customer. I want that in wizard customer name(partner_id) should be auto-filled when the user opens it. So, how can I do that?
Wizard file code is:
class RentalPackWizard(models.TransientModel):
_name = "rental.pack.wizard"
_description = "Rental Pack Wizard"
"""#api.model
def _get_default_partner(self):
partner = self.env['res.partner'].search([()], limit=1)
return partner"""
ser6_partner_id = fields.Many2one('res.partner', string='Customer')# , default=_get_default_partner)
Also Attached image for problem
In your xml use context to pass values.
Example:
context="{'default_partner_id':partner_id}"

Stop creating mail message and Followers in perticular model in odoo

When I create new sale order,it also creates the mail messages and followers at bottom of form view.
But I want to make that system should not create mail message and followers while users creates or writes data of "sale.order" model.
How can I stop such message and followers creation .?
Just need to apply context in create and write method of that model.
#api.model
def create(self,vals):
res=super(sale_order,self.with_context({'mail_create_nosubscribe':True,'tracking_disable':True})).create(vals)
return res
#api.multi
def write(self,vals):
res=super(sale_order,self.with_context({'mail_create_nosubscribe':True,'tracking_disable':True})).write(vals)
return res
If you just want to remove it from the view then override the template and remove the fields named:
message_follower_ids
message_ids
These two fields are responsible for the view part.
Code to remove the fields:
<xpath expr="//field[#name='message_follower_ids']" position="replace"/>
Will this be fine or should I tell you how to update the record at model level?

How to get data is on a remote server using odoo

On a remote server I have data in this form:
A project contains one or more tranches
A tranche contains one or more units
On my class odoo, I added these fields:
project_id: this is a many2one field to select the project. I can get back the list of project from the remote server
Tranche_id: A many2one field to select the tranche. I need when I change the project, this field should just list the tranches of the selected project.
Entity_id: A many2one field to select the Entity. I need when I change the tranche, this field should just list the entities of the selected tranche.
Is it possible to implement the many2one relation on Odoo with the constraint that the data is on a remote server and consumable REST API?
Help me please
Kindly.
Try this code:
#api.onchange('project_id')
def onchange_project_id(self):
res = {}
if self.object_id:
res['domain'] = {'tranche_id': [('project_id', '=', self.project_id.id)]}
return res
#api.onchange('tranche_id')
def onchange_tranche_id(self):
res = {}
if self.object_id:
res['domain'] = {'entity_id': [('tranche_id', '=', self.tranche_id.id)]}
return res
It may help in your case.

How can I create an alias name of a relational field in Odoo?

I need to create a model, to have backward compatibility with older field names.
This way,
I can develop modules that could read the "new" fields, but migrating the old ones is not necessary for this to work.
This works only for reading or presenting the fields, but not for writing them.
So I thought it would be good to create an alias for each field, and made this:
from openerp import models, fields, api
class backward_compatibility(models.Model):
_description = 'Backward compatibility'
_inherit = 'account.invoice'
new_document_class_id = fields.Integer(
compute='_comp_new_doc_class', string='Tipo')
new_document_number = fields.Char(
compute='_comp_new_doc_number', string='Folio')
#api.multi
def _comp_new_doc_class(self):
for record in self:
try:
record.new_document_class_id = record.old_document_class_id
except:
pass
#api.multi
def _comp_new_doc_number(self):
for record in self:
try:
record.new_document_number = record.old_document_number
except:
pass
This approach works for the Char field, but it doesn't for the Integer (Many2one).
What ideas do you have to make this work? Should I replicate the relationship in the new field?
oldname: the previous name of this field, so that ORM can rename it automatically at migration
Try to use "oldname". I saw this in the core modules. Never used personally.
_inherit = 'res.partner'
_columns = {
'barcode' : fields.char('Barcode', help="BarCode", oldname='ean13'),
}
Also dummy fields are user to help with backward compatibility.
'pricelist_id': fields.dummy(string='Pricelist', relation='product.pricelist', type='many2one'),