summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2024-08-14 13:31:36 +0700
committerstephanchrst <stephanchrst@gmail.com>2024-08-14 13:31:36 +0700
commited089761d43b20ecc4190ca9d88a0bdb769d81f2 (patch)
tree6f5ed6967a4aa20e5773561f7a6b129d91b23311 /indoteknik_custom/models
parent513d2b473f4fbf7245c35289e2a3215c5da556a6 (diff)
parentc091a99de4e3c3bb4f85a8b0c91d75735ebefbd4 (diff)
Merge branch 'production' into feature/calculate_selling_price
# Conflicts: # indoteknik_custom/views/website_user_cart.xml
Diffstat (limited to 'indoteknik_custom/models')
-rwxr-xr-xindoteknik_custom/models/__init__.py1
-rw-r--r--indoteknik_custom/models/account_move_due_extension.py1
-rw-r--r--indoteknik_custom/models/approval_date_doc.py49
-rw-r--r--indoteknik_custom/models/automatic_purchase.py2
-rw-r--r--indoteknik_custom/models/logbook_bill.py4
-rw-r--r--indoteknik_custom/models/purchasing_job.py33
-rw-r--r--indoteknik_custom/models/res_partner.py14
-rwxr-xr-xindoteknik_custom/models/sale_order.py8
-rw-r--r--indoteknik_custom/models/stock_picking.py24
-rw-r--r--indoteknik_custom/models/voucher.py1
10 files changed, 120 insertions, 17 deletions
diff --git a/indoteknik_custom/models/__init__.py b/indoteknik_custom/models/__init__.py
index 116354d6..e9ce587c 100755
--- a/indoteknik_custom/models/__init__.py
+++ b/indoteknik_custom/models/__init__.py
@@ -124,3 +124,4 @@ from . import report_logbook_bill
from . import sale_order_multi_uangmuka_penjualan
from . import shipment_group
from . import sales_order_reject
+from . import approval_date_doc
diff --git a/indoteknik_custom/models/account_move_due_extension.py b/indoteknik_custom/models/account_move_due_extension.py
index c9af7f8d..0399c6a2 100644
--- a/indoteknik_custom/models/account_move_due_extension.py
+++ b/indoteknik_custom/models/account_move_due_extension.py
@@ -24,6 +24,7 @@ class DueExtension(models.Model):
('approved', 'Approved'),
], string='Approval Status', readonly=True, copy=False, index=True, tracking=3)
day_extension = fields.Selection([
+ ('1', '1 Hari'),
('3', '3 Hari'),
('7', '7 Hari'),
('14', '14 Hari'),
diff --git a/indoteknik_custom/models/approval_date_doc.py b/indoteknik_custom/models/approval_date_doc.py
new file mode 100644
index 00000000..e00b7416
--- /dev/null
+++ b/indoteknik_custom/models/approval_date_doc.py
@@ -0,0 +1,49 @@
+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 ApprovalDateDoc(models.Model):
+ _name = "approval.date.doc"
+ _description = "Approval Date Doc"
+ _rec_name = 'number'
+
+ picking_id = fields.Many2one('stock.picking', string='Picking')
+ number = fields.Char(string='Document No', index=True, copy=False, readonly=True, tracking=True)
+ driver_departure_date = fields.Datetime(
+ string='Driver Departure Date',
+ copy=False
+ )
+ state = fields.Selection([('draft', 'Draft'), ('done', 'Done')], string='State', default='draft', tracking=True)
+ approve_date = fields.Datetime(string='Approve Date', copy=False)
+ approve_by = fields.Many2one('res.users', string='Approve By', copy=False)
+ sale_id = fields.Many2one('sale.order', string='Sale Order')
+
+ @api.onchange('picking_id')
+ def onchange_picking_id(self):
+ if self.picking_id:
+ self.sale_id = self.picking_id.sale_id.id
+
+ def check_invoice_so_picking(self):
+ for rec in self:
+ invoice = self.env['account.move'].search_count([('sale_id', '=', rec.picking_id.sale_id.id)])
+
+ if invoice < 1:
+ raise UserError("Sales Order Belum Memiliki Invoice, Anda Bisa Edit Di DO nya langsung")
+
+ def button_approve(self):
+ if not self.env.user.is_accounting:
+ raise UserError("Hanya Accounting Yang Bisa Approve")
+ self.check_invoice_so_picking
+ self.picking_id.driver_departure_date = self.driver_departure_date
+ self.state = 'done'
+ self.approve_date = datetime.utcnow()
+ self.approve_by = self.env.user.id
+
+ @api.model
+ def create(self, vals):
+ vals['number'] = self.env['ir.sequence'].next_by_code('approval.date.doc') or '0'
+ result = super(ApprovalDateDoc, self).create(vals)
+ return result
diff --git a/indoteknik_custom/models/automatic_purchase.py b/indoteknik_custom/models/automatic_purchase.py
index 73416c48..f5b1baf9 100644
--- a/indoteknik_custom/models/automatic_purchase.py
+++ b/indoteknik_custom/models/automatic_purchase.py
@@ -396,7 +396,7 @@ class AutomaticPurchase(models.Model):
domain = [
('product_id', '=', line.product_id.id)
]
- sale = self.env['v.sales.outstanding'].search(domain, limit=1)
+ sale = self.env['v.sales.outstanding'].search(domain, order='sale_order_create_date desc', limit=1)
existing_match = self.env['automatic.purchase.sales.match'].search([
('automatic_purchase_id', '=', self.id),
diff --git a/indoteknik_custom/models/logbook_bill.py b/indoteknik_custom/models/logbook_bill.py
index 578ad59b..bb956092 100644
--- a/indoteknik_custom/models/logbook_bill.py
+++ b/indoteknik_custom/models/logbook_bill.py
@@ -22,7 +22,9 @@ class LogbookBill(models.TransientModel):
('product_id', '=', line.product_id.id),
], order='id desc', limit=1)
total += line.quantity_done * po.price_unit
- return total
+ total_with_tax = total * 1.11
+ return total_with_tax
+
def create_logbook_bill(self):
logbook_line = self.logbook_bill_line
diff --git a/indoteknik_custom/models/purchasing_job.py b/indoteknik_custom/models/purchasing_job.py
index 373e469a..6e4f239d 100644
--- a/indoteknik_custom/models/purchasing_job.py
+++ b/indoteknik_custom/models/purchasing_job.py
@@ -183,6 +183,7 @@ class OutstandingSales(models.Model):
outgoing = fields.Float(string='Outgoing')
brand = fields.Char(string='Brand')
invoice_partner = fields.Char(string='Invoice Partner')
+ sale_order_create_date = fields.Datetime(string='Sale Order Create Date')
def init(self):
tools.drop_view_if_exists(self.env.cr, self._table)
@@ -199,19 +200,23 @@ class OutstandingSales(models.Model):
so.partner_invoice_id,
sp.origin,
rp2.name as salesperson,
- coalesce(pp.default_code, pt.default_code) as item_code, pt.name as product,
- sm.product_uom_qty as outgoing, xm.x_name as brand, rp.name as invoice_partner
- from stock_move sm
- join stock_picking sp on sp.id = sm.picking_id
- join sale_order_line sol on sol.id = sm.sale_line_id
- join sale_order so on so.id = sol.order_id
- join res_partner rp on rp.id = so.partner_invoice_id
- join res_users ru on ru.id = so.user_id
- join res_partner rp2 on rp2.id = ru.partner_id
- join product_product pp on pp.id = sm.product_id
- join product_template pt on pt.id = pp.product_tmpl_id
- left join x_manufactures xm on xm.id = pt.x_manufacture
- where sp.state in ('draft', 'waiting', 'confirmed', 'assigned')
- and sp.name like '%OUT%'
+ coalesce(pp.default_code, pt.default_code) as item_code,
+ pt.name as product,
+ sm.product_uom_qty as outgoing,
+ xm.x_name as brand,
+ rp.name as invoice_partner,
+ so.create_date as sale_order_create_date
+ from stock_move sm
+ join stock_picking sp on sp.id = sm.picking_id
+ join sale_order_line sol on sol.id = sm.sale_line_id
+ join sale_order so on so.id = sol.order_id
+ join res_partner rp on rp.id = so.partner_invoice_id
+ join res_users ru on ru.id = so.user_id
+ join res_partner rp2 on rp2.id = ru.partner_id
+ join product_product pp on pp.id = sm.product_id
+ join product_template pt on pt.id = pp.product_tmpl_id
+ left join x_manufactures xm on xm.id = pt.x_manufacture
+ where sp.state in ('draft', 'waiting', 'confirmed', 'assigned')
+ and sp.name like '%OUT%'
)
""")
diff --git a/indoteknik_custom/models/res_partner.py b/indoteknik_custom/models/res_partner.py
index 19699aab..39faf9d3 100644
--- a/indoteknik_custom/models/res_partner.py
+++ b/indoteknik_custom/models/res_partner.py
@@ -48,6 +48,15 @@ class ResPartner(models.Model):
user_payment_terms_purchase = fields.Many2one('res.users', string='Users Update Payment Terms')
date_payment_terms_purchase = fields.Datetime(string='Date Update Payment Terms')
+ def write(self, vals):
+ res = super(ResPartner, self).write(vals)
+
+ if 'property_payment_term_id' in vals:
+ if not self.env.user.is_accounting and vals['property_payment_term_id'] != 26:
+ raise UserError('Hanya Finance Accounting yang dapat merubah payment term')
+
+ return res
+
@api.constrains('property_payment_term_id')
def updated_by_payment_term(self):
for rec in self:
@@ -111,5 +120,10 @@ class ResPartner(models.Model):
if self._name == 'res.partner':
raise UserError('Maaf anda tidak bisa delete contact')
+ @api.onchange('customer_type')
+ def _onchange_customer_type(self):
+ if self.customer_type == 'nonpkp':
+ self.npwp = '00.000.000.0-000.000'
+
diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py
index 5badacba..0b0a679f 100755
--- a/indoteknik_custom/models/sale_order.py
+++ b/indoteknik_custom/models/sale_order.py
@@ -501,6 +501,10 @@ class SaleOrder(models.Model):
raise UserError("Credit Limit pada Master Data Customer harus diisi")
if order.payment_term_id != partner.property_payment_term_id:
raise UserError("Payment Term berbeda pada Master Data Customer")
+ if (partner.customer_type == 'pkp' or order.customer_type == 'pkp') and order.npwp != partner.npwp:
+ raise UserError("NPWP berbeda pada Master Data Customer")
+ if (partner.customer_type == 'pkp' or order.customer_type == 'pkp') and order.sppkp != partner.sppkp:
+ raise UserError("SPPKP berbeda pada Master Data Customer")
if not order.client_order_ref and order.create_date > datetime(2024, 6, 27):
raise UserError("Customer Reference kosong, di isi dengan NO PO jika PO tidak ada mohon ditulis Tanpa PO")
@@ -518,6 +522,10 @@ class SaleOrder(models.Model):
raise UserError("Credit Limit pada Master Data Customer harus diisi")
if order.payment_term_id != partner.property_payment_term_id:
raise UserError("Payment Term berbeda pada Master Data Customer")
+ if (partner.customer_type == 'pkp' or order.customer_type == 'pkp') and order.npwp != partner.npwp:
+ raise UserError("NPWP berbeda pada Master Data Customer")
+ if (partner.customer_type == 'pkp' or order.customer_type == 'pkp') and order.sppkp != partner.sppkp:
+ raise UserError("SPPKP berbeda pada Master Data Customer")
if not order.client_order_ref and order.create_date > datetime(2024, 6, 27):
raise UserError("Customer Reference kosong, di isi dengan NO PO jika PO tidak ada mohon ditulis Tanpa PO")
diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py
index c151a543..5029a770 100644
--- a/indoteknik_custom/models/stock_picking.py
+++ b/indoteknik_custom/models/stock_picking.py
@@ -26,7 +26,10 @@ class StockPicking(models.Model):
# Delivery Order
driver_departure_date = fields.Datetime(
string='Driver Departure Date',
- readonly=True,
+ copy=False
+ )
+ arrival_time = fields.Datetime(
+ string='Jam Kedatangan',
copy=False
)
driver_arrival_date = fields.Datetime(
@@ -91,6 +94,21 @@ class StockPicking(models.Model):
date_availability = fields.Datetime(string="Date Availability", copy=False, tracking=True)
sale_order = fields.Char(string='Matches SO', copy=False)
printed_sj = fields.Boolean('Printed Surat Jalan', help='flag which is internal use or not')
+ invoice_status = fields.Selection([
+ ('upselling', 'Upselling Opportunity'),
+ ('invoiced', 'Fully Invoiced'),
+ ('to invoice', 'To Invoice'),
+ ('no', 'Nothing to Invoice')
+ ], string='Invoice Status', related="sale_id.invoice_status")
+
+ @api.constrains('driver_departure_date')
+ def constrains_driver_departure_date(self):
+ self.date_doc_kirim = self.driver_departure_date
+
+ @api.constrains('arrival_time')
+ def constrains_arrival_time(self):
+ if self.arrival_time > datetime.datetime.utcnow():
+ raise UserError('Jam kedatangan harus kurang dari Effective Date')
def reset_status_printed(self):
for rec in self:
@@ -341,6 +359,9 @@ class StockPicking(models.Model):
if not self.picking_code:
self.picking_code = self.env['ir.sequence'].next_by_code('stock.picking.code') or '0'
+ if not self.arrival_time and 'BU/IN/' in self.name:
+ raise UserError('Jam Kedatangan harus diisi')
+
if self.picking_type_id.code == 'incoming' and self.group_id.id == False and self.is_internal_use == False:
raise UserError(_('Tidak bisa Validate jika tidak dari Document SO / PO'))
@@ -372,6 +393,7 @@ class StockPicking(models.Model):
res = super(StockPicking, self).button_validate()
self.calculate_line_no()
+ self.date_done = datetime.datetime.utcnow()
return res
@api.model
diff --git a/indoteknik_custom/models/voucher.py b/indoteknik_custom/models/voucher.py
index 66f763e0..c21ef209 100644
--- a/indoteknik_custom/models/voucher.py
+++ b/indoteknik_custom/models/voucher.py
@@ -90,6 +90,7 @@ class Voucher(models.Model):
'image': ir_attachment.api_image('voucher', 'image', self.id),
'name': self.name,
'code': self.code,
+ 'apply_type': self.apply_type,
'description': self.description,
'remaining_time': self._res_remaining_time(),
}