Odoo Help


How to create SQL Constraints in Wizard with models.TransientModel ?

on 2/14/15, 5:46 AM 1,064 views

I have create SQL Constraint in wizard stock.transfer_detail_items. It is work, but the data still save to database. Why it is like that? Because it should not be saved to the database. What is wrong?

class stock_transfer_details_items(models.TransientModel):
    _name = 'stock.transfer_details_items'
    _description = 'Picking wizard items'

    transfer_id = fields.Many2one('stock.wtc_transfer_details', 'Transfer')
    packop_id = fields.Many2one('stock.pack.operation', 'Operation')
    product_id = fields.Many2one('product.product', 'Product')
    product_uom_id = fields.Many2one('product.uom', 'Product Unit of Measure')
    engine_number = fields.Char('Engine Number')
    chassis_number = fields.Char('Chassis Number')
    quantity = fields.Float('Quantity', digits_compute=dp.get_precision('Product Unit of Measure'), default = 1.0)
    package_id = fields.Many2one('stock.quant.package', 'Source package', domain="['|', ('location_id', 'child_of', sourceloc_id), ('location_id','=',False)]")
    lot_id = fields.Many2one('stock.production.lot', 'Lot/Serial Number')
    sourceloc_id = fields.Many2one('stock.location', 'Source Location', required=True)
    destinationloc_id = fields.Many2one('stock.location', 'Destination Location', required=True)
    result_package_id = fields.Many2one('stock.quant.package', 'Destination package', domain="['|', ('location_id', 'child_of', destinationloc_id), ('location_id','=',False)]")
    date = fields.Datetime('Date')
    owner_id = fields.Many2one('res.partner', 'Owner', help="Owner of the quants")
    branch_id = fields.Many2one('wtc.branch', 'Branch')
    division = fields.Selection([
                                 ], 'Division')
    _sql_constraints = [
                        ('unique_transfer_engine', 'unique(transfer_id,engine_number)', 'Ditemukan Engine Number duplicate, Silahkan cek kembali !'),
                        ('unique_transfer_chassis', 'unique(transfer_id,chassis_number)', 'Ditemukan Chassis Number duplicate, Silahkan cek kembali !'),

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 2/14/15, 5:46 AM
Seen: 1064 times
Last updated: 7/10/15, 10:50 AM