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

I have two model and code is given below 


class SellProduct (models.Model):
_name = 'sell.product'
_rec_name = 'product_seq'
# def product (self): # name = self.env ['product.create']. search ([]) # print (name ) product_seq = fields.Many2one ( comodel_name = "product.create" , string = "Product ID" , required = False ,) product_name = fields.Char ( related = 'product_seq.product_name' , string = "Product Name" ,required = False ,)






sell_product_quantity = fields.Integer ( string = "Product Quantity" , required = True ,)
gold_price_new = fields.Integer ( string = "Total Price" , compute = 'compute_price' , store = True ,)

payment = fields.Integer ( string = "Payment" )
due_amount = fields.Integer (string = "Due" , compute = 'due_compute' , store = True )
company_id = fields.Many2one ( 'res.company' , 'Company' , required = True , index = True ,
default = lambda self: self.env.company .id)
currency_id = fields.Many2one ( "res.currency" , string = "Currency" , readonly = True ,
default = lambdaself: self.env.company.currency_id.id, required = True )

sell_line = fields.Many2one ( comodel_name = "product.create" , string = "Sell Line" , required = False ,)





class ProductCreate (models.Model):
_name = 'product.create'
_inherit = [ 'mail.thread' , 'mail.activity.mixin' ,]
_rec_name = 'product_seq'
@ api.depends ( 'create_sell_line' , 'create_sell_line. sell_product_quantity ' ) def update_value ( self ): for rec in self : rec.product_quantity_new = rec.create_sell_line.sell_product_quantity product_seq = fields.Char ( string = ' PID ' ,required =





True , copy = False ,
randomly = True , index = True ,
default = lambda self: _ ( 'New' ))
product_name = fields.Char ( string = "Product Name" )
product_image = fields.Binary ( string = "Product Image " )
product_quantity_new = fields.Integer ( compute = 'update_value' )
product_quantity = fields.Integer ( string = "Product Quantity" ,)
gold_quality = fields.Selection ( string = "Gold Quality" , selection = [( '18k' , '18K' ), ( '21k' , '21K' ), ( '22k' , '22K' )],
required = True ,)
gold_rate = fields.Integer ( string = "Gold Rate" )
gold_weight = fields.Float ( string = "Weight / Gram" , required = True )
making_cost = fields.Integer ( string = " Making Cost")
gold_price = fields.Integer ( string = "Sub-total Price" , compute = 'compute_sub_total_price' , store = True )
tax = fields.Integer ( string = "Tax" , )
tax_cal = fields.Integer ( string = "tax Calculation" , compute = 'compute_tax' , store = True )
total_cost = fields.Integer ( string= "Total Price" , compute = 'compute_total_price' , store = True )

create_sell_line = fields.One2many ( comodel_name = "sell.product" , inverse_name = "sell_line" , string = "create sell line" ,
required = False ,)


Fom  sell.product model, sell_product_quantity field's value will be store product.create model's prouct_quantity_new field
How to solve this problem?

Avatar
Discard
Best Answer

Hi Arjun,

        I guess  "sell.product"  model is given as one2many  to  "product.create",  so you must take the sum of the values of sell_product_quantity  and store it in  "prouct_quantity_new" .

So just try,

class ProductCreate(models.Model): 

    _name = 'product.create' 

    @api.multi

    @api.depends('create_sell_line', 'create_sell_line.sell_product_quantity')

    def update_value(self):

        for each in self:

            each.product_quantity_new = sum(line.sell_product_quantity for line in each.create_sell_line)

 Hope it helps,

Thanks





Avatar
Discard
Author

Thank you sir for your answer.

But it is not working.

Actually Firstly I create a product in product.create model here has a unique ID for each product.

After that in the sell.product model here I will sell that product by selecting product ID and here I give product quantity. Suppose when I created product product quantity was 30 now I will sell 20 after that my product is 10?

Kindly see this and if you can solve this problem kindly

Related Posts Replies Views Activity
2
Jun 23
2974
1
Aug 23
1917
0
Apr 23
1697
1
Dec 21
3400
1
Sep 21
3837