summaryrefslogtreecommitdiff
path: root/fixco_api/models/sale.py
blob: 198689a3aa2dba7ab34b04c5ed88892fda2b0b1c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from odoo import models


class SaleOrderLine(models.Model):
    _inherit = 'sale.order.line'

    def api_single_response(self, line):
        tax = 0
        for taxes in line.tax_id:
            tax = taxes.name
        data = {
            'product_id': line.product_id.id,
            'product_name': line.product_id.name,
            'qty': line.product_uom_qty,
            'tax': tax,
            'price_unit': line.price_unit,
            'price_subtotal': line.price_subtotal,
            'price_tax': line.price_tax,
            'price_total': line.price_total,
            'price_reduce': line.price_reduce,
            'price_reduce_taxinc': line.price_reduce_taxinc,
            'price_reduce_taxexcl': line.price_reduce_taxexcl,
            'discount': line.discount,
        }
        return data


class SaleOrder(models.Model):
    _inherit = 'sale.order'

    def api_create_invoices(self, sale_order_id):
        sale_orders = self.env['sale.order'].search([('id', '=', sale_order_id)])

        # if self.advance_payment_method == 'delivered':
        invoices = sale_orders._create_invoices(final=True)
        data = []
        for invoice in invoices:
            invoice.action_post()
            data.append({
                'id': invoice.id,
                'name': invoice.name,
                'ref': invoice.ref,
                'state': invoice.state
            })
        return data