diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2023-02-20 11:29:15 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2023-02-20 11:29:15 +0700 |
| commit | b9cf801ad8334fe1b5be7b13b5d0483303c297c7 (patch) | |
| tree | 07f4ed201c8a1af2ef9c778f3e78a9b2fdb8ae20 | |
| parent | 28a205be163323cfad8596bbbcf0d1f7b3e4b993 (diff) | |
add details in sale order api midtrans
| -rw-r--r-- | indoteknik_api/controllers/api_v1/sale_order.py | 1 | ||||
| -rw-r--r-- | indoteknik_api/models/sale_order.py | 15 |
2 files changed, 16 insertions, 0 deletions
diff --git a/indoteknik_api/controllers/api_v1/sale_order.py b/indoteknik_api/controllers/api_v1/sale_order.py index f6c6faa5..727d49b7 100644 --- a/indoteknik_api/controllers/api_v1/sale_order.py +++ b/indoteknik_api/controllers/api_v1/sale_order.py @@ -41,6 +41,7 @@ class SaleOrder(controller.Controller): 'state': sale.state, 'product_name': product_name, 'product_not_in_id': product_not_in_id, + 'details': [request.env['sale.order.line'].api_single_response(x, context='with_detail') for x in sale.order_line] }) return self.response(data) diff --git a/indoteknik_api/models/sale_order.py b/indoteknik_api/models/sale_order.py index 7ce8ff61..66ef27fa 100644 --- a/indoteknik_api/models/sale_order.py +++ b/indoteknik_api/models/sale_order.py @@ -63,3 +63,18 @@ class SaleOrder(models.Model): data_with_detail['invoices'].append(self.env['account.move'].api_v1_single_response(invoice)) data.update(data_with_detail) return data + + +class SaleOrderLine(models.Model): + _inherit = 'sale.order.line' + + def api_single_response(self, sale_order_line, context=False): + data = { + 'image': self.env['ir.attachment'].api_image('product.template', 'image_128', sale_order_line.product_id.product_tmpl_id.id), + 'item_code': sale_order_line.product_id.default_code, + 'product_name': sale_order_line.product_id.name, + 'price_before_discount': sale_order_line.price_unit * sale_order_line.product_uom_qty, + 'price_after_discount': sale_order_line.price_total, + 'tax': sale_order_line.price_tax + } + return data |
