diff options
| author | Azka Nathan <darizkyfaz@gmail.com> | 2025-07-04 09:18:50 +0700 |
|---|---|---|
| committer | Azka Nathan <darizkyfaz@gmail.com> | 2025-07-04 09:18:50 +0700 |
| commit | 38ba3d7f5b59a4444d9eb953a6c83e4ab6015ba6 (patch) | |
| tree | d03c644fb17f21197bd4f12ea13ea79783e527b7 | |
| parent | 498b7f73857189d1b22204c3f71f35d03ec4afb7 (diff) | |
approval payment term
| -rwxr-xr-x | indoteknik_custom/__manifest__.py | 1 | ||||
| -rwxr-xr-x | indoteknik_custom/models/__init__.py | 1 | ||||
| -rw-r--r-- | indoteknik_custom/models/approval_payment_term.py | 82 | ||||
| -rwxr-xr-x | indoteknik_custom/security/ir.model.access.csv | 1 | ||||
| -rw-r--r-- | indoteknik_custom/views/account_move.xml | 1 | ||||
| -rw-r--r-- | indoteknik_custom/views/approval_payment_term.xml | 74 | ||||
| -rw-r--r-- | indoteknik_custom/views/ir_sequence.xml | 10 |
7 files changed, 170 insertions, 0 deletions
diff --git a/indoteknik_custom/__manifest__.py b/indoteknik_custom/__manifest__.py index ad019d4b..17cec7b6 100755 --- a/indoteknik_custom/__manifest__.py +++ b/indoteknik_custom/__manifest__.py @@ -156,6 +156,7 @@ 'views/stock_backorder_confirmation_views.xml', 'views/barcoding_product.xml', 'views/project_views.xml', + 'views/approval_payment_term.xml', 'report/report.xml', 'report/report_banner_banner.xml', 'report/report_banner_banner2.xml', diff --git a/indoteknik_custom/models/__init__.py b/indoteknik_custom/models/__init__.py index 605d1016..83392d42 100755 --- a/indoteknik_custom/models/__init__.py +++ b/indoteknik_custom/models/__init__.py @@ -151,3 +151,4 @@ from . import account_payment_register from . import stock_inventory from . import sale_order_delay from . import approval_invoice_date +from . import approval_payment_term diff --git a/indoteknik_custom/models/approval_payment_term.py b/indoteknik_custom/models/approval_payment_term.py new file mode 100644 index 00000000..81eb1908 --- /dev/null +++ b/indoteknik_custom/models/approval_payment_term.py @@ -0,0 +1,82 @@ +from odoo import models, api, fields +from odoo.exceptions import AccessError, UserError, ValidationError +from datetime import timedelta, date, datetime +import logging + +_logger = logging.getLogger(__name__) + +class ApprovalPaymentTerm(models.Model): + _name = "approval.payment.term" + _description = "Approval Payment Term" + _inherit = ['mail.thread'] + _rec_name = 'number' + + number = fields.Char(string='Document No', index=True, copy=False, readonly=True, tracking=True) + partner_id = fields.Many2one('res.partner', string='Partner', copy=False) + property_payment_term_id = fields.Many2one('account.payment.term', string='Payment Term', copy=False, tracking=True) + parent_id = fields.Many2one('res.partner', string='Related Company', copy=False) + blocking_stage = fields.Float(string='Blocking Amount', + help="Cannot make sales once the selected " + "customer is crossed blocking amount." + "Set its value to 0.00 to disable " + "this feature", tracking=True, copy=False) + warning_stage = fields.Float(string='Warning Amount', + help="A warning message will appear once the " + "selected customer is crossed warning " + "amount. Set its value to 0.00 to" + " disable this feature", tracking=True, copy=False) + active_limit = fields.Boolean('Active Credit Limit', copy=False, tracking=True) + approve_sales_manager = fields.Boolean('Approve Sales Manager', tracking=True, copy=False) + approve_finance = fields.Boolean('Approve Finance', tracking=True, copy=False) + approve_leader = fields.Boolean('Approve Pimpinan', tracking=True, copy=False) + reason = fields.Text('Reason', tracking=True) + approve_date = fields.Datetime('Approve Date') + + + @api.constrains('partner_id') + def constrains_partner_id(self): + if self.partner_id: + self.parent_id = self.partner_id.parent_id.id if self.partner_id.parent_id else None + self.blocking_stage = self.partner_id.blocking_stage + self.warning_stage = self.partner_id.warning_stage + self.active_limit = self.partner_id.active_limit + self.property_payment_term_id = self.partner_id.property_payment_term_id.id + + def button_approve(self): + user = self.env.user + is_it = user.has_group('indoteknik_custom.group_role_it') + + if is_it or user.id == 19: + self.approve_sales_manager = True + return + + if is_it or user.id == 688 and self.approve_sales_manager: + self.approve_finance = True + return + + if is_it or user.id == 7 and self.approve_sales_manager and self.approve_finance: + self.approve_leader = True + + if not is_it or not self.approve_finance: + raise UserError('Harus Approval Finance!!') + if not is_it or not self.approve_leader: + raise UserError('Harus Approval Pimpinan!!') + + if user.id == 7: + if not self.approve_finance: + raise UserError('Belum Di Approve Oleh Finance') + + if self.approve_leader == True: + self.partner_id.write({ + 'blocking_stage': self.blocking_stage, + 'warning_stage': self.warning_stage, + 'active_limit': self.active_limit, + 'property_payment_term_id': self.property_payment_term_id.id + }) + self.approve_date = datetime.utcnow() + + @api.model + def create(self, vals): + vals['number'] = self.env['ir.sequence'].next_by_code('approval.payment.term') or '0' + result = super(ApprovalPaymentTerm, self).create(vals) + return result diff --git a/indoteknik_custom/security/ir.model.access.csv b/indoteknik_custom/security/ir.model.access.csv index 3dabae6d..2b970cfd 100755 --- a/indoteknik_custom/security/ir.model.access.csv +++ b/indoteknik_custom/security/ir.model.access.csv @@ -182,3 +182,4 @@ access_sale_order_delay,sale.order.delay,model_sale_order_delay,,1,1,1,1 access_production_purchase_match,access.production.purchase.match,model_production_purchase_match,,1,1,1,1 access_image_carousel,access.image.carousel,model_image_carousel,,1,1,1,1 access_v_sale_notin_matchpo,access.v.sale.notin.matchpo,model_v_sale_notin_matchpo,,1,1,1,1 +access_approval_payment_term,access.approval.payment.term,model_approval_payment_term,,1,1,1,1 diff --git a/indoteknik_custom/views/account_move.xml b/indoteknik_custom/views/account_move.xml index ad52a74a..2f52b3d9 100644 --- a/indoteknik_custom/views/account_move.xml +++ b/indoteknik_custom/views/account_move.xml @@ -70,6 +70,7 @@ <field name="so_shipping_covered_by"/> <field name="so_delivery_amt"/> <field name="flag_delivery_amt"/> + <field name="length_of_payment"/> </field> <field name="amount_untaxed" position="after"> <field name="other_subtotal" invisible="1"/> diff --git a/indoteknik_custom/views/approval_payment_term.xml b/indoteknik_custom/views/approval_payment_term.xml new file mode 100644 index 00000000..87c77385 --- /dev/null +++ b/indoteknik_custom/views/approval_payment_term.xml @@ -0,0 +1,74 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<odoo> + <record id="approval_payment_term_tree" model="ir.ui.view"> + <field name="name">approval.payment.term.tree</field> + <field name="model">approval.payment.term</field> + <field name="arch" type="xml"> + <tree default_order="create_date desc"> + <field name="number"/> + <field name="partner_id"/> + <field name="parent_id"/> + <field name="property_payment_term_id"/> + <field name="approve_date" optional="hide"/> + <field name="approve_sales_manager" optional="hide"/> + <field name="approve_finance" optional="hide"/> + <field name="approve_leader" optional="hide"/> + <field name="create_uid" optional="hide"/> + </tree> + </field> + </record> + + <record id="approval_payment_term_form" model="ir.ui.view"> + <field name="name">approval.payment.term.form</field> + <field name="model">approval.payment.term</field> + <field name="arch" type="xml"> + <form> + <header> + <button name="button_approve" + string="Approve" + type="object" + attrs="{'invisible': [('approve_leader', '=', True)]}" + /> + </header> + <sheet string="Approval Payment Term"> + <group> + <group> + <field name="number" readonly="1"/> + <field name="partner_id"/> + <field name="parent_id" readonly="1"/> + <field name="blocking_stage" attrs="{'readonly': [('number', '=', False)]}"/> + <field name="warning_stage" attrs="{'readonly': [('number', '=', False)]}"/> + <field name="property_payment_term_id" attrs="{'readonly': [('number', '=', False)]}"/> + <field name="active_limit" attrs="{'readonly': [('number', '=', False)]}"/> + </group> + <group> + <field name="reason"/> + <field name="approve_date" readonly="1"/> + <field name="approve_sales_manager" readonly="1"/> + <field name="approve_finance" readonly="1"/> + <field name="approve_leader" readonly="1"/> + </group> + </group> + </sheet> + <div class="oe_chatter"> + <field name="message_follower_ids" widget="mail_followers"/> + <field name="message_ids" widget="mail_thread"/> + </div> + </form> + </field> + </record> + + <record id="approval_payment_term_action" model="ir.actions.act_window"> + <field name="name">Approval Payment Term</field> + <field name="type">ir.actions.act_window</field> + <field name="res_model">approval.payment.term</field> + <field name="view_mode">tree,form</field> + </record> + + <menuitem id="menu_approval_payment_term" name="Approval Payment Term" + parent="account.menu_finance_receivables" + action="approval_payment_term_action" + sequence="100" + /> + +</odoo>
\ No newline at end of file diff --git a/indoteknik_custom/views/ir_sequence.xml b/indoteknik_custom/views/ir_sequence.xml index bb8848c4..a0f5fc6b 100644 --- a/indoteknik_custom/views/ir_sequence.xml +++ b/indoteknik_custom/views/ir_sequence.xml @@ -150,6 +150,16 @@ <field name="number_increment">1</field> <field name="active">True</field> </record> + + <record id="sequence_approval_payment_term" model="ir.sequence"> + <field name="name">Approval Payment Term</field> + <field name="code">approval.payment.term</field> + <field name="prefix">APP/%(year)s/</field> + <field name="padding">5</field> + <field name="number_next">1</field> + <field name="number_increment">1</field> + <field name="active">True</field> + </record> <record id="sequence_commision_fee" model="ir.sequence"> <field name="name">Customer Commision Fee</field> |
