Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
3 Odpowiedzi
6666 Widoki

Here is The problems


class Purchase(models.Model):

    _name = 'purchase'

    name = fields.Char(string="name")

    orderDate = fields.Date(string="Order Date")

    salesPerson = fields.Char(string="Sales Person", required=True)

    expiredDate = fields.Date(string="Expired Date", required=True)

    company = fields.Char(string="Company", related="customer_id.company", readonly=True)

    tax = fields.Float(string ="Tax")

    unTax = fields.Float(string="Untaxed", compute="_total_price")

    amount_total =  fields.Float(compute='_compute_amount_total', string="Total")

    orderNumber = fields.Char(string="Order Number")

    subpurchase_ids = fields.One2many('subpurchase', 'purchase_id', string="Purchase Lines")

    customer_id = fields.Many2one('customer', string='partner', required=True)

   

    

    state = fields.Selection([

            ('new', 'New'), 

            ('draft', 'Draft'),

            ('validate', 'Validated'),

            ('cancel', 'Cancelled')], 

            string='Status', required=False, readonly=True, copy=False, default='new')

    

    @api.onchange('tax', 'unTax')       

    @api.multi

    def _compute_amount_total(self):

        self.amount_total = self.unTax + self.tax

        

    @api.depends('subpurchase_ids', 'subpurchase_ids.amount') #tambah kalo butuh relasi tambahan

    @api.multi

    def _total_price(self):

        for purchase in self :

            total_price = 0

            for subpurchase in purchase.subpurchase_ids:

                total_price += subpurchase.amount

            purchase.unTax = total_price


class SubPurchase(models.Model):
    _name = 'subpurchase'

    category = fields.Char(string="Category", related="product_id.category", readonly=True)
    amount = fields.Float(compute='_compute_amount', string="Amount")
    quantity = fields.Integer(string="Quantity")
    codeItem = fields.Char(string="Code Item", readonly=True, related="product_id.codeItem")
    price = fields.Float(string="Item Price", readonly=True, related="product_id.price")
    sequence = fields.Char(string="Sequence")
    purchase_id = fields.Many2one('purchase', string="Customer")

 
    @api.multi
    @api.onchange('quantity', 'price')
    def _compute_amount(self):
        self.amount = self.quantity * self.price


i have an order lines so when i want add an item 2 or more the error come out ? how to fix this ?
example in order line i add an item Mouse 1 and save <= OKEY but when i add another item mouse 2 so there have a 2 item when i save this error come out 
Awatar
Odrzuć

Thanks to you all for answer this question

Najlepsza odpowiedź

I think you need to use a for loop in `_compute_amount_total` and `_compute_amount` methods.

Just give it a try and if this does not solve the issue, please post the traceback.

Awatar
Odrzuć
Najlepsza odpowiedź

Hi,

The Single ton error can be sorted out by iterating the self over a for loop or by using self.ensure_one() . In your code, at a first glance everything seems to be fine, you have iterated the self and the one2many lines. So will suggest you to cross check the code by putting the print statements in the code and see.

Suppose if any of the variables is getting the value as sale.order(38, 39), just a sample, then make sure that the value is then iterated over the loop such a way that we will get sale.order(38) and sale.order(39).

If you have the added the fields amount and amount_total in the Tree views, make sure that the corresponding compute function is also iterated over the for loop.


@api.onchange('tax', 'unTax')       
@api.multi
def _compute_amount_total(self):
for rec in self:
rec.amount_total = rec.unTax + rec.tax


Thanks

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
2
lut 23
7907
0
wrz 20
3188
2
mar 15
5767
3
cze 24
1641
problem backup Rozwiązane
3
cze 24
6404