This question has been flagged
1 Reply
5679 Views

I had inherited a pos.order But i am unable to add customer of current order in it .if anyone know that how i can fetch the Customer by using the order id.I am beginner in odoo and python . But i tried to understand the pos.order class  but i am not successful in it .  

class pos_order (models.Model):

    _inherit = 'pos.order'



    @ api.multi

    def print_pos_report (self):

     return self.env ['report']. get_action (self, 'point_of_sale.pos_invoice_report')




    @ api.multi

    def print_pos_receipt (self):

        output = []

        discount = 0

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

        orderlines = self.env ['pos.order.line']. search ([('order_id', '=', order_id.id)])

        payments = self.env ['account.bank.statement.line']. search ([('pos_statement_id', '=', order_id.id)])

        paymentlines = []

        subtotal = 0

        tax = 0

        change = 0

        for payment in payments:

            if payment.amount> 0:

                temp = {

                    'amount': payment.amount,

                    'name': payment.journal_id.name

                }

                paymentlines.append (temp)

            else:

                change + = payment.amount

             

        for orderline in orderlines:

            new_vals = {

                'product_id': orderline.product_id.name,

                'qty': orderline.qty,

                'price_unit': orderline.price_unit,

                'discount': orderline.discount,

                }

                

            discount + = (orderline.price_unit * orderline.qty * orderline.discount) / 100

            subtotal + = orderline.price_subtotal

            tax + = (orderline.price_subtotal_incl - orderline.price_subtotal)

            

            output.append (new_vals)


        return [output, discount, paymentlines, change, subtotal, tax]

Avatar
Discard
Best Answer

Well, since you inherit pos_order, you have access to all fields of pos_order...

So if you want the current partner_id, just use "self.partner_id" (beware not to have multiple records in self...)


By the way, i did not look through your whole code but even in the beginning there are big mistakes ;)


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

==> why do you do this? If you use "self.id" in the search function, you are searching "yourself"...

you can use order_id = self, or even more easier, user 'self' in place of order_id


orderlines = self.env ['pos.order.line']. search ([('order_id', '=', order_id.id)])

==> again, you do not need to search to achieve this, since you can directly link the lines from "self"

orderlines = self.lines

Avatar
Discard
Author

I am a totally beginner with python and odoo . So i am trying to learn it with quick examples. Thanks for your time . can you suggest me some strong reference which relates to my task(I want reprint the orders at pos session i had successful in listing orders and printing single order now i want to access customer of the order)