diff options
| author | Miqdad <ahmadmiqdad27@gmail.com> | 2025-07-23 13:11:17 +0700 |
|---|---|---|
| committer | Miqdad <ahmadmiqdad27@gmail.com> | 2025-07-23 13:11:17 +0700 |
| commit | 1dbe906db264189b69a10633b3e7516650b3dfc5 (patch) | |
| tree | fdfb8781b18bdfcf46e5a6c380400d6651525f3b | |
| parent | 365c9cbd0be8749873e4ec9953588d6b1b395677 (diff) | |
<miqdad> PO fix sequence on create and add vendor name
| -rw-r--r-- | indoteknik_custom/models/tukar_guling_po.py | 45 | ||||
| -rw-r--r-- | indoteknik_custom/views/ir_sequence.xml | 2 | ||||
| -rw-r--r-- | indoteknik_custom/views/tukar_guling_po.xml | 9 |
3 files changed, 41 insertions, 15 deletions
diff --git a/indoteknik_custom/models/tukar_guling_po.py b/indoteknik_custom/models/tukar_guling_po.py index 72417a72..d2390854 100644 --- a/indoteknik_custom/models/tukar_guling_po.py +++ b/indoteknik_custom/models/tukar_guling_po.py @@ -10,7 +10,9 @@ _logger = logging.getLogger(__name__) class TukarGulingPO(models.Model): _name = 'tukar.guling.po' _description = 'Tukar Guling PO' + _inherit = ['mail.thread', 'mail.activity.mixin'] + vendor_id = fields.Many2one('res.partner', string='Vendor Name', readonly=True) origin = fields.Char(string='Origin PO') is_po = fields.Boolean('Is PO', default=True) is_so = fields.Boolean('Is SO', default=False) @@ -50,21 +52,22 @@ class TukarGulingPO(models.Model): @api.model def create(self, vals): # Generate sequence number + # ven_name = self.origin.search([('name', 'ilike', vals['origin'])]) if not vals.get('name') or vals['name'] == 'New': - sequence = self.env['ir.sequence'].search([('code', '=', 'tukar.guling.po')], limit=1) - if sequence: - vals['name'] = sequence.next_by_id() - else: - # Fallback jika sequence belum dibuat - vals['name'] = self.env['ir.sequence'].next_by_code('tukar.guling.po') or 'new' + vals['name'] = self.env['ir.sequence'].next_by_code('tukar.guling.po') # Auto-fill origin from operations if not vals.get('origin') and vals.get('operations'): picking = self.env['stock.picking'].browse(vals['operations']) if picking.origin: vals['origin'] = picking.origin + if picking.group_id.id: + vals['vendor_id'] = picking.group_id.partner_id.id + + res = super(TukarGulingPO, self).create(vals) + res.message_post(body=_("Tukar Guling PO Created By %s") % self.env.user.name) - return super(TukarGulingPO, self).create(vals) + return res @api.constrains('return_type', 'operations') def _check_bill_on_revisi_po(self): @@ -377,16 +380,16 @@ class TukarGulingPO(models.Model): if rec.state == 'approval_purchase': if not rec.env.user.has_group('indoteknik_custom.group_role_sales'): raise UserError("Hanya Sales Manager yang boleh approve tahap ini.") - rec.state = 'approval_logistic' - - elif rec.state == 'approval_logistic': - if not rec.env.user.has_group('indoteknik_custom.group_role_logistic'): - raise UserError("Hanya Logistic Manager yang boleh approve tahap ini.") rec.state = 'approval_finance' elif rec.state == 'approval_finance': if not rec.env.user.has_group('indoteknik_custom.group_role_fat'): raise UserError("Hanya Finance Manager yang boleh approve tahap ini.") + rec.state = 'approval_logistic' + + elif rec.state == 'approval_logistic': + if not rec.env.user.has_group('indoteknik_custom.group_role_logistic'): + raise UserError("Hanya Logistic Manager yang boleh approve tahap ini.") rec.state = 'done' rec._create_pickings() else: @@ -594,3 +597,21 @@ class TukarGulingLinePO(models.Model): class StockPicking(models.Model): _inherit = 'stock.picking' tukar_guling_po_id = fields.Many2one('tukar.guling.po', string='Tukar Guling PO Ref') + + + def button_validate(self): + res = super(StockPicking, self).button_validate() + for picking in self: + if picking.tukar_guling_po_id: + message = _( + "📦 <b>%s</b> Validated by <b>%s</b> Status Changed <b>%s</b> at <b>%s</b>." + ) % ( + picking.name, + # picking.picking_type_id.name, + picking.env.user.name, + picking.state, + fields.Datetime.now().strftime("%d/%m/%Y %H:%M") + ) + picking.tukar_guling_po_id.message_post(body=message) + + return res
\ No newline at end of file diff --git a/indoteknik_custom/views/ir_sequence.xml b/indoteknik_custom/views/ir_sequence.xml index 03cfbc1a..257f0d27 100644 --- a/indoteknik_custom/views/ir_sequence.xml +++ b/indoteknik_custom/views/ir_sequence.xml @@ -204,7 +204,7 @@ <field name="name">Pengajuan Return SO</field> <field name="code">tukar.guling</field> <field name="active">TRUE</field> - <field name="prefix">CCM/%(year)s/</field> + <field name="prefix">CCM/%(year)s/%(month)s/</field> <field name="padding">5</field> <field name="number_next">1</field> <field name="number_increment">1</field> diff --git a/indoteknik_custom/views/tukar_guling_po.xml b/indoteknik_custom/views/tukar_guling_po.xml index 0e29e965..266f4eea 100644 --- a/indoteknik_custom/views/tukar_guling_po.xml +++ b/indoteknik_custom/views/tukar_guling_po.xml @@ -28,7 +28,7 @@ <field name="ba_num" string="Nomor BA"/> <field name="return_type" string="Return Type"/> <field name="state" widget="badge" - decoration-info="state in ('draft', 'approval_purchase', 'approval_logistic','approval_finance')" + decoration-info="state in ('draft', 'approval_purchase', 'approval_finance','approval_logistic')" decoration-success="state == 'done'" decoration-muted="state == 'cancel'" /> @@ -47,7 +47,7 @@ attrs="{'invisible': [('state', '!=', 'draft')]}"/> <button name="action_approve" string="Approve" type="object" class="btn-primary" - attrs="{'invisible': [('state', 'not in', ['approval_purchase', 'approval_logistic', 'approval_finance'])]}"/> + attrs="{'invisible': [('state', 'not in', ['approval_purchase', 'approval_finance', 'approval_logistic'])]}"/> <button name="action_cancel" string="Cancel" type="object" class="btn-secondary" attrs="{'invisible': [('state', '=', 'cancel')]}" @@ -76,6 +76,7 @@ </div> <group> <group> + <field name="vendor_id" readonly="1"/> <field name="date" string="Date" readonly="1"/> <field name="return_type"/> <!-- <field name="ort_num" readonly="1"/>--> @@ -109,6 +110,10 @@ </page> </notebook> </sheet> + <div class="oe_chatter"> + <field name="message_follower_ids" widget="mail_followers"/> + <field name="message_ids" widget="mail_thread"/> + </div> </form> </field> </record> |
