diff options
| author | Azka Nathan <darizkyfaz@gmail.com> | 2024-09-13 10:25:03 +0700 |
|---|---|---|
| committer | Azka Nathan <darizkyfaz@gmail.com> | 2024-09-13 10:25:03 +0700 |
| commit | b473179e5adde097bc9ec43ee4566b850937f1ed (patch) | |
| tree | 692846858d335ac67fa3881c390188144f3c2090 | |
| parent | 5c6098158ab0f82437aa24e947a66b78b21b6bd7 (diff) | |
unreserve
| -rw-r--r-- | indoteknik_custom/models/approval_unreserve.py | 9 | ||||
| -rwxr-xr-x | indoteknik_custom/models/sale_order.py | 10 | ||||
| -rw-r--r-- | indoteknik_custom/models/sale_order_line.py | 2 | ||||
| -rw-r--r-- | indoteknik_custom/models/stock_move.py | 2 | ||||
| -rw-r--r-- | indoteknik_custom/views/approval_unreserve.xml | 9 | ||||
| -rwxr-xr-x | indoteknik_custom/views/sale_order.xml | 5 |
6 files changed, 16 insertions, 21 deletions
diff --git a/indoteknik_custom/models/approval_unreserve.py b/indoteknik_custom/models/approval_unreserve.py index a8f9fd3b..8c232d9c 100644 --- a/indoteknik_custom/models/approval_unreserve.py +++ b/indoteknik_custom/models/approval_unreserve.py @@ -22,6 +22,7 @@ class ApprovalUnreserve(models.Model): request_date = fields.Date(string="Request Date", default=fields.Date.today, tracking=True) approved_by = fields.Many2one('res.users', string="Approved By", readonly=True, tracking=True) picking_id = fields.Many2one('stock.picking', string="Picking", tracking=True) + user_id = fields.Many2one('res.users', string="User", readonly=True, tracking=True) rejection_reason = fields.Text(string="Rejection Reason", tracking=True) @api.constrains('picking_id') @@ -40,6 +41,8 @@ class ApprovalUnreserve(models.Model): 'move_id': move.id }) + self.user_id = self.picking_id.sale_id.user_id.id + @api.model def create(self, vals): if vals.get('number', 'New') == 'New': @@ -50,6 +53,9 @@ class ApprovalUnreserve(models.Model): self.write({'state': 'waiting_approval'}) def action_approve(self): + if self.env.user.id != self.user_id.id: + raise UserError("Hanya Sales nya yang bisa approve.") + if self.state != 'waiting_approval': raise UserError("Approval can only be done in 'Waiting for Approval' state") self.write({ @@ -60,6 +66,9 @@ class ApprovalUnreserve(models.Model): self._trigger_unreserve() def action_reject(self, reason): + if self.env.user.id != self.user_id.id: + raise UserError("Hanya Sales nya yang bisa reject.") + if self.state != 'waiting_approval': raise UserError("Rejection can only be done in 'Waiting for Approval' state") self.write({ diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 023cc5e6..0690ffa2 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -113,16 +113,6 @@ class SaleOrder(models.Model): use_button = fields.Boolean(string='Using Calculate Selling Price', copy=False) unreserve_id = fields.Many2one('stock.picking', 'Unreserve Picking') voucher_shipping_id = fields.Many2one(comodel_name='voucher', string='Voucher Shipping', copy=False) - - def do_unreserve(self): - user_id = self.env.user.id - if user_id != self.user_id.id and user_id != self.helper_by_id.id: - raise UserError(_("Only the user who created the picking can unreserve it.")) - - if self.unreserve_id and self.unreserve_id.state == 'assigned': - self.unreserve_id.with_context({'darimana': 'sale.order'}).do_unreserve() - else: - raise UserError(_("Picking not found.")) def _compute_date_kirim(self): for rec in self: diff --git a/indoteknik_custom/models/sale_order_line.py b/indoteknik_custom/models/sale_order_line.py index a64a744c..50438dbe 100644 --- a/indoteknik_custom/models/sale_order_line.py +++ b/indoteknik_custom/models/sale_order_line.py @@ -348,7 +348,7 @@ class SaleOrderLine(models.Model): def validate_line(self): for line in self: - if line.product_id.id in [385544, 224484]: + if line.product_id.id in [385544, 224484, 417724]: raise UserError('Produk Sementara Tidak Bisa Di Confirm atau Ask Approval') if not line.product_id or line.product_id.type == 'service': continue diff --git a/indoteknik_custom/models/stock_move.py b/indoteknik_custom/models/stock_move.py index 6c44f8a6..cd061946 100644 --- a/indoteknik_custom/models/stock_move.py +++ b/indoteknik_custom/models/stock_move.py @@ -14,7 +14,7 @@ class StockMove(models.Model): if move.state == 'cancel' or (move.state == 'done' and move.scrapped): continue elif move.state == 'done': - raise UserError(_("You cannot unreserve a stock move that has been set to 'Done'.")) + raise UserError("You cannot unreserve a stock move that has been set to 'Done'.") if product and move.product_id != product: continue # Skip moves that don't match the specified product diff --git a/indoteknik_custom/views/approval_unreserve.xml b/indoteknik_custom/views/approval_unreserve.xml index 08a5b49e..5ffa1294 100644 --- a/indoteknik_custom/views/approval_unreserve.xml +++ b/indoteknik_custom/views/approval_unreserve.xml @@ -39,11 +39,12 @@ <sheet> <group> <group> - <field name="number"/> - <field name="request_date"/> + <field name="number" readonly="1"/> + <field name="request_date" readonly="1"/> <field name="picking_id"/> - <field name="state"/> - <field name="approved_by"/> + <field name="user_id" readonly="1"/> + <field name="state" readonly="1"/> + <field name="approved_by" readonly="1"/> </group> </group> <notebook> diff --git a/indoteknik_custom/views/sale_order.xml b/indoteknik_custom/views/sale_order.xml index 99f56136..83474df7 100755 --- a/indoteknik_custom/views/sale_order.xml +++ b/indoteknik_custom/views/sale_order.xml @@ -11,11 +11,6 @@ string="Create No" type="object" /> - <button name="do_unreserve" - string="Unreserve Picking" - type="object" - attrs="{'invisible': [('state', 'in', ['draft', 'cancel', 'done'])]}" - /> <button name="sale_order_approve" string="Ask Approval" type="object" |
