diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2023-06-05 11:00:42 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2023-06-05 11:00:42 +0700 |
| commit | 25ad8547cc4aab608478d52352d834579f26c88d (patch) | |
| tree | 692b8b41032137f3e29606c44d00e986b130af9e | |
| parent | 7ffcb706cfbacdc7abf11c239073acadaae469a7 (diff) | |
add validation qty invoice cant greater than qty order in invoice customer and vendor
| -rw-r--r-- | indoteknik_custom/models/account_move.py | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/indoteknik_custom/models/account_move.py b/indoteknik_custom/models/account_move.py index 56f3e82c..c2e93632 100644 --- a/indoteknik_custom/models/account_move.py +++ b/indoteknik_custom/models/account_move.py @@ -33,13 +33,36 @@ class AccountMove(models.Model): return res def action_post(self): + if self._name != 'account.move': + return super(AccountMove, self).action_post() + + # validation cant qty invoice greater than qty order + if self.move_type == 'out_invoice': + query = ["&",("name","=",self.invoice_origin),"|",("state","=","sale"),("state","=","done")] + sale_order = self.env['sale.order'].search(query, limit=1) + sum_qty_invoice = sum_qty_order = 0 + for line in sale_order.order_line: + sum_qty_invoice += line.qty_invoiced + sum_qty_order += line.product_uom_qty + if sum_qty_invoice > sum_qty_order: + raise UserError('Error Qty Invoice akan lebih besar dari Qty Order jika lanjut Posting') + elif self.move_type == 'in_invoice': + query = ["&",("name","=",self.invoice_origin),"|",("state","=","purchase"),("state","=","done")] + purchase_order = self.env['purchase.order'].search(query, limit=1) + sum_qty_invoice = sum_qty_order = 0 + for line in purchase_order.order_line: + sum_qty_invoice += line.qty_invoiced + sum_qty_order += line.product_uom_qty + if sum_qty_invoice > sum_qty_order: + raise UserError('Error Qty Invoice akan lebih besar dari Qty Order jika lanjut Posting') + res = super(AccountMove, self).action_post() # if not self.env.user.is_accounting: # raise UserError('Hanya Accounting yang bisa Posting') - if self._name == 'account.move': - for entry in self: - for line in entry.line_ids: - line.date_maturity = entry.date + # if self._name == 'account.move': + for entry in self: + for line in entry.line_ids: + line.date_maturity = entry.date return res def _compute_invoice_day_to_due(self): |
