Skip to Content
Menu
This question has been flagged
1 Reply
2113 Views

I have  three classesProductModel,BuyProduct,SoldProduct

when a user buys a  product i need  to remove item from ProductModel and insert to SoldProduct.

class ProductModel(models.Model):

_name = "product.model"

product_name=feilds.Char("Product")

product_id = feilds.Char("Id")

_sql_constraints = [

        ('uniq_product_id', 'unique(product_id)', 'id already exists'),

    ]


    @api.model

    def create(self, vals):

        id = randrange(1000, 10000)

        vals['product_id'] = "PR" + str(id)

        return super(ProductModel, self).create(vals)


class BuyProduct(models.Model):

_name = buyproduct.model

user_Name = fields.Many2one('user.model',string="Name")

    product = fields.Many2many('product.model',string="Product")

    Date = fields.Datetime(default = fields.Datetime.now(),string="Selling Date",readonly=True)

    return_Before =fields.Datetime(default = lambda self:(datetime.datetime.now() + datetime.timedelta(days=7)),string="return_Before",readonly=True)

class SoldProduct(models.Model):

_name = soldproduct.model

product_name = fields.Char("Product")

product_id = fields.Char("Id")


Thanks in advance,

Ramanathan Lakshmanan

Avatar
Discard

The idea is to override odoo default methods (create, write, unlink): https://goo.gl/4BkizH

Best Answer

Hello,

You can call unlink and create methods of the respective models to create and delete a records.

But why don't you use another field like state for showing whether the product is sold or not.

Avatar
Discard