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

hi all , iam new to this platform , iam facing an issue with odoo 12 , what iam trying to achieve is i want to subtract a product subtotal value from another product value in same line in sale order line, and i want to display that value in the report, i have wrote a function below when i update my module  




    @api.depends('price_subtotal', 'price_unit')

    def _compute_trans(self):

product_id = self.env['product.product'].search([('default_code','=','INSURANCE')])

        if product_id:

        for line in self:

                got_product_id = self.env['sale.order.line'].search([('product_id','=',product_id.id),

                                                                 ('order_id','=',self.id)],limit=1)

                sum_dummy = self.subtotal - got_product_id.price_subtotal 

            line.update({'sum_fr ':trans_dummy})

                         


    sum_fr = fields.Float(string='Sum' ,store=True, readonly=True, compute='_compute_trans')




iam getting this error:

    raise ValueError("Expected singleton: %s" % record)

ValueError: Expected singleton: sale.order.line(743, 745, 746, 739, 741, 742, 737, 738, 735, 736, 733, 734, 730, 732, 728, 729, 726, 727, 725, 721, 722, 723, 719, 720, 715, 717, 718, 713, 714, 706, 707, 708, 701, 702, 703, 704, 705, 697, 698, 694, 695, 696, 692, 693, 690, 691, 687, 689, 688, 685, 686, 682, 683, 684, 679, 680, 677, 678, 675, 676, 673, 674, 671, 672, 670, 668, 669, 666, 667, 663, 665, 661, 662, 659, 660, 656, 658, 653, 654, 651, 652, 649, 655, 647, 648, 645, 646, 642, 643, 640, 644, 641, 638, 639, 636, 637, 634, 635, 632, 633, 629, 630, 631, 681, 628, 625, 626, 627, 619, 620, 617, 618, 615, 616, 613, 614, 610, 611, 612, 608, 609, 605, 606, 607, 601, 602, 603, 595, 596, 597, 591, 592, 593, 589, 590, 585, 586, 587, 588, 573, 572, 569, 570, 567, 568, 551, 566, 544, 557, 542, 543, 536, 539, 540, 532, 533, 534, 529, 530, 531, 527, 528, 526, 524, 525, 541, 523, 522, 521, 520, 518, 519, 517, 516, 515, 514, 511, 510, 509, 507, 505, 504, 500, 499, 496, 497, 498, 491, 492, 495, 489, 490, 487, 488, 485, 483, 484, 481, 482, 478, 479, 480, 475, 476, 477, 472, 473, 474, 469, 471, 468, 467, 464, 461, 462, 454, 455, 456, 457, 458, 451, 452, 453, 448, 449, 450, 445, 446, 447, 439, 440, 441, 426, 427, 428, 423, 424, 425, 420, 421, 422, 417, 418, 419, 413, 416, 385, 386, 387, 538, 378, 376, 377, 373, 374, 375, 371, 372, 370, 384, 357, 356, 355, 354, 353, 352, 351, 350, 349, 348, 347, 346, 345, 344, 343, 342, 341, 339, 338, 337, 336, 334, 333, 332, 331, 330, 335, 329, 328, 326, 325, 311, 312, 291, 297, 294, 295, 296, 298, 299, 300, 301, 302, 303, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288, 272, 273, 274, 275, 276, 277, 278, 257, 258, 265, 259, 260, 261, 262, 263, 264, 266, 267, 268, 269, 270, 271, 240, 247, 241, 242, 243, 244, 245, 246, 248, 249, 250, 251, 252, 253, 254, 255, 256, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 340, 222, 221, 218, 217, 216, 215, 214, 213, 212, 211, 210, 209, 208, 207, 206, 205, 204, 203, 202, 201, 200, 199, 198, 195, 196, 197, 192, 191, 190, 189, 194, 188, 187, 186, 185, 184, 313, 314, 315, 316, 317, 318, 319, 320, 321, 183, 182, 181, 180, 179, 178, 193, 177, 176, 175, 174, 173, 172, 171, 170, 169, 168, 167, 166, 165, 164, 163, 162, 161, 160, 159, 158, 157, 156, 155, 154, 153, 151, 152, 149, 304, 305, 306, 307, 308, 309, 310, 148, 147, 146, 145, 144, 143, 140, 141, 142, 137, 138, 139, 135, 136, 134, 133, 132, 131, 130, 128, 129, 126, 127, 125, 124, 123, 122, 121, 120, 119, 118, 117, 116, 114, 113, 112, 110, 111, 107, 109, 106, 105, 104, 103, 100, 99, 97, 98, 96, 94, 86, 87, 88, 81, 82, 80, 78, 79, 76, 77, 74, 73, 72, 71, 70, 69, 68, 67, 66, 65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 52, 53, 51, 49, 50, 48, 46, 47, 45, 42, 43, 44, 39, 40, 41, 37, 38, 35, 36, 28, 27, 26, 25, 24, 19, 20, 21, 22, 23, 16, 17, 18, 15, 14, 10, 11, 12, 13, 9, 8, 5, 6, 4, 2, 3, 1)


someone help with this , i know its accessing multiple records but how to do this or achieve by end goal


Avatar
Discard

Hello,

Could you try changing:

sum_dummy = self.subtotal - got_product_id.price_subtotal

To:

sum_dummy = line.subtotal - got_product_id.price_subtotal

Thanks,

Author

hi jack , thanks for the reply i tried what u mentioned but still getting the same error

Best Answer

Hi,

got_product_id = self.env['sale.order.line'].search([('product_id','=',product_id.id),('order_id','=',self.id)],limit=1)
sum_dummy = self.subtotal - got_product_id.price_subtotal 

rewrite above lines as follows:-

got_product_id = self.env['sale.order.line'].search([('product_id','=',product_id.id),
('order_id','=',line.order_id.id)],limit=1)sum_dummy = line.subtotal - got_product_id.price_subtotal

Regards

Avatar
Discard
Related Posts Replies Views Activity
3
Nov 23
15304
3
Nov 24
21056
1
Apr 23
4562
2
Dec 22
5495
1
Oct 22
868