diff options
| author | Azka Nathan <darizkyfaz@gmail.com> | 2024-09-17 14:05:31 +0700 |
|---|---|---|
| committer | Azka Nathan <darizkyfaz@gmail.com> | 2024-09-17 14:05:31 +0700 |
| commit | f0aaf4476c8b92cb68503e9760216ca20fe4e34d (patch) | |
| tree | 9199754e2bba9f467ccae8b5cb4f01b2b882f492 | |
| parent | 2e9f95e8201692317d1ce23f6992fdb0e37dc95c (diff) | |
api check_tempo and add type promotion on sale order
| -rw-r--r-- | indoteknik_api/controllers/api_v1/partner.py | 28 | ||||
| -rwxr-xr-x | indoteknik_custom/models/sale_order.py | 11 | ||||
| -rwxr-xr-x | indoteknik_custom/views/sale_order.xml | 1 |
3 files changed, 40 insertions, 0 deletions
diff --git a/indoteknik_api/controllers/api_v1/partner.py b/indoteknik_api/controllers/api_v1/partner.py index 69a2f861..83f92a19 100644 --- a/indoteknik_api/controllers/api_v1/partner.py +++ b/indoteknik_api/controllers/api_v1/partner.py @@ -164,4 +164,32 @@ class Partner(controller.Controller): }) return self.response(data) + + @http.route(prefix + 'check/<partner_id>/tempo', auth='public', methods=['GET', 'OPTIONS']) + @controller.Controller.must_authorized() + def get_check_tempo_partner(self, **kw): + partner_id = int(kw.get('partner_id')) + + partner = request.env['res.partner'].search([('id', '=', partner_id)], limit=1) + if not partner: + return self.response(code=404, description='Partner not found') + + partner = partner.parent_id or partner + + if any(line.days == 0 for line in partner.property_payment_term_id.line_ids): + return self.response(code=402, description='Partner not tempo') + + result_tempo = sum(m.amount_total_signed for m in request.env['account.move'].search([('partner_id', '=', partner.id), ('payment_state', '=', 'not_paid'), ('state', '=', 'posted')])) + + remaining_limit = partner.blocking_stage - result_tempo if partner.active_limit else None + + data = { + 'name': partner.name, + 'amount_due': result_tempo, + 'remaining_limit': remaining_limit + } + + return self.response(data) + + diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 6348328e..43ee3ef9 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -115,6 +115,17 @@ class SaleOrder(models.Model): margin_after_delivery_purchase = fields.Float(string='Margin After Delivery Purchase', compute='_compute_margin_after_delivery_purchase') percent_margin_after_delivery_purchase = fields.Float(string='% Margin After Delivery Purchase', compute='_compute_margin_after_delivery_purchase') purchase_delivery_amt = fields.Float(string='Purchase Delivery Amount', compute='_compute_purchase_delivery_amount') + type_promotion = fields.Char(string='Type Promotion', compute='_compute_type_promotion') + + def _compute_type_promotion(self): + for rec in self: + promotion_types = [] + for promotion in rec.order_promotion_ids: + for line_program in promotion.program_line_id: + if line_program.promotion_type: + promotion_types.append(dict(line_program._fields['promotion_type'].selection).get(line_program.promotion_type)) + + rec.type_promotion = ', '.join(promotion_types) def _compute_purchase_delivery_amount(self): for order in self: diff --git a/indoteknik_custom/views/sale_order.xml b/indoteknik_custom/views/sale_order.xml index e772dcae..f2789254 100755 --- a/indoteknik_custom/views/sale_order.xml +++ b/indoteknik_custom/views/sale_order.xml @@ -32,6 +32,7 @@ <field name="delivery_amt"/> <field name="fee_third_party"/> <field name="total_percent_margin"/> + <field name="type_promotion"/> <label for="voucher_id"/> <div class="o_row"> <field name="voucher_id" id="voucher_id" attrs="{'readonly': ['|', ('state', 'not in', ['draft', 'sent']), ('applied_voucher_id', '!=', False)]}"/> |
