Odoo Help

Welcome!

This community 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.

2

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

By
Miftah
on 2/14/15, 5:46 AM 993 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([
                                 ('Unit','Unit'),
                                 ('Sparepart','Sparepart'),
                                 ('Umum','Umum')
                                 ], '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 community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

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