summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models
diff options
context:
space:
mode:
Diffstat (limited to 'indoteknik_custom/models')
-rwxr-xr-xindoteknik_custom/models/__init__.py1
-rw-r--r--indoteknik_custom/models/account_move.py14
-rwxr-xr-xindoteknik_custom/models/purchase_order.py1
-rw-r--r--indoteknik_custom/models/purchasing_job.py45
-rw-r--r--indoteknik_custom/models/purchasing_job_multi_update.py2
-rwxr-xr-xindoteknik_custom/models/sale_order.py4
-rw-r--r--indoteknik_custom/models/sale_order_line.py25
-rw-r--r--indoteknik_custom/models/shipment_group.py81
-rw-r--r--indoteknik_custom/models/stock_picking.py3
9 files changed, 134 insertions, 42 deletions
diff --git a/indoteknik_custom/models/__init__.py b/indoteknik_custom/models/__init__.py
index ffd1b645..10f4acee 100755
--- a/indoteknik_custom/models/__init__.py
+++ b/indoteknik_custom/models/__init__.py
@@ -120,3 +120,4 @@ from . import purchase_order_multi_uangmuka2
from . import logbook_bill
from . import report_logbook_bill
from . import sale_order_multi_uangmuka_penjualan
+from . import shipment_group
diff --git a/indoteknik_custom/models/account_move.py b/indoteknik_custom/models/account_move.py
index fbadd2aa..a7010bbe 100644
--- a/indoteknik_custom/models/account_move.py
+++ b/indoteknik_custom/models/account_move.py
@@ -78,18 +78,20 @@ class AccountMove(models.Model):
})
return attachment
- # @api.constrains('efaktur_document')
+ @api.constrains('efaktur_document')
def send_scheduled_email(self):
# Get the records for which emails need to be sent
records = self.search([('id', 'in', self.ids)])
+
template = self.env.ref('indoteknik_custom.mail_template_efaktur_document')
for record in records:
- attachment = self.generate_attachment(record)
- email_values = {
- 'attachment_ids': [(4, attachment.id)]
- }
- template.send_mail(record.id, email_values=email_values, force_send=True)
+ if record.invoice_payment_term_id.id == 26:
+ attachment = self.generate_attachment(record)
+ email_values = {
+ 'attachment_ids': [(4, attachment.id)]
+ }
+ template.send_mail(record.id, email_values=email_values, force_send=True)
@api.model
def create(self, vals):
diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py
index 4a029441..32ddf1e5 100755
--- a/indoteknik_custom/models/purchase_order.py
+++ b/indoteknik_custom/models/purchase_order.py
@@ -487,7 +487,6 @@ class PurchaseOrder(models.Model):
for purchasing_job in purchasing_job_state:
purchasing_job.unlink()
-
def _send_po_not_sync(self):
# Mengirim data ke model Po Sync Price jika harga po dan purchase pricelist tidak singkron
for line in self.order_line:
diff --git a/indoteknik_custom/models/purchasing_job.py b/indoteknik_custom/models/purchasing_job.py
index 40061d22..373e469a 100644
--- a/indoteknik_custom/models/purchasing_job.py
+++ b/indoteknik_custom/models/purchasing_job.py
@@ -41,13 +41,14 @@ class PurchasingJob(models.Model):
}
def init(self):
- query = """
+ tools.drop_view_if_exists(self.env.cr, self._table)
+ self.env.cr.execute("""
CREATE OR REPLACE VIEW %s AS (
WITH latest_purchase_orders AS (
SELECT
pol.product_id,
po.user_id,
- ROW_NUMBER() OVER (PARTITION BY pol.product_id ORDER BY po.create_date DESC) AS order_rank
+ ROW_NUMBER() OVER (PARTITION BY po.partner_id ORDER BY po.create_date DESC) AS order_rank
FROM purchase_order po
RIGHT JOIN purchase_order_line pol ON pol.order_id = po.id
LEFT JOIN res_partner rp ON rp.id = po.partner_id
@@ -69,26 +70,11 @@ class PurchasingJob(models.Model):
LEFT JOIN sale_order_line sol ON sol.id = vso.sale_line_id
) AS sub
WHERE sub.vendor_id IS NOT NULL
- ),
- unique_sub AS (
- SELECT DISTINCT
- vso.product_id,
- sol.vendor_id
- FROM v_sales_outstanding vso
- LEFT JOIN sale_order_line sol ON sol.id = vso.sale_line_id
- WHERE sol.vendor_id IS NOT NULL
- ),
- latest_po_filtered AS (
- SELECT
- product_id,
- user_id
- FROM latest_purchase_orders
- WHERE order_rank = 1
)
SELECT
pmp.product_id AS id,
pmp.product_id,
- MAX(sub.vendor_id) AS vendor_id,
+ sub.vendor_id,
pmp.brand,
pmp.item_code,
pmp.product,
@@ -98,23 +84,30 @@ class PurchasingJob(models.Model):
pmp.action,
MAX(pjs.status_apo) AS status_apo,
MAX(pjs.note) AS note,
- MAX(ru.user_id) AS purchase_representative_id
+ ru.user_id AS purchase_representative_id
FROM v_procurement_monitoring_by_product pmp
LEFT JOIN purchasing_job_state pjs ON pjs.purchasing_job_id = pmp.product_id
- LEFT JOIN unique_sub sub ON sub.product_id = pmp.product_id
- LEFT JOIN latest_po_filtered po ON po.product_id = pmp.product_id
+ LEFT JOIN (
+ SELECT
+ vso.product_id,
+ sol.vendor_id
+ FROM v_sales_outstanding vso
+ LEFT JOIN sale_order_line sol ON sol.id = vso.sale_line_id
+ ) AS sub ON sub.product_id = pmp.product_id
+ LEFT JOIN latest_purchase_orders po ON po.product_id = pmp.product_id
LEFT JOIN random_user_ids ru ON ru.vendor_id = sub.vendor_id OR (ru.vendor_id IS NULL AND sub.vendor_id != 9688)
WHERE pmp.action = 'kurang'
- AND sub.vendor_id IS NOT NULL
+ AND sub.vendor_id IS NOT NULL
GROUP BY
pmp.product_id,
pmp.brand,
pmp.item_code,
pmp.product,
- pmp.action
- )""" % self._table
-
- self.env.cr.execute(query)
+ pmp.action,
+ sub.vendor_id,
+ ru.user_id
+ )
+ """ % self._table)
def open_form_multi_generate_request_po(self):
diff --git a/indoteknik_custom/models/purchasing_job_multi_update.py b/indoteknik_custom/models/purchasing_job_multi_update.py
index 80a43e45..deba960a 100644
--- a/indoteknik_custom/models/purchasing_job_multi_update.py
+++ b/indoteknik_custom/models/purchasing_job_multi_update.py
@@ -18,7 +18,7 @@ class PurchasingJobMultiUpdate(models.TransientModel):
('purchasing_job_id', '=', product.id)
])
- # purchasing_job_state.unlink()
+ purchasing_job_state.unlink()
purchasing_job_state.create({
'purchasing_job_id': product.id,
diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py
index ac81737d..0d28e677 100755
--- a/indoteknik_custom/models/sale_order.py
+++ b/indoteknik_custom/models/sale_order.py
@@ -201,6 +201,10 @@ class SaleOrder(models.Model):
@api.model
def action_multi_update_state(self):
for sale in self:
+ for picking_ids in sale.picking_ids:
+ if not picking_ids.state == 'cancel':
+ raise UserError('DO harus cancel terlebih dahulu')
+
sale.update({
'state': 'cancel',
})
diff --git a/indoteknik_custom/models/sale_order_line.py b/indoteknik_custom/models/sale_order_line.py
index d362d573..1fee041d 100644
--- a/indoteknik_custom/models/sale_order_line.py
+++ b/indoteknik_custom/models/sale_order_line.py
@@ -115,25 +115,33 @@ class SaleOrderLine(models.Model):
[('vendor_id', '=', self.product_id.x_manufacture.override_vendor_id.id),
('product_id', '=', self.product_id.id)],
limit=1, order='count_trx_po desc, count_trx_po_vendor desc')
- self.purchase_price = self._get_valid_purchase_price(purchase_price)
+ price, taxes = self._get_valid_purchase_price(purchase_price)
+ self.purchase_price = price
+ self.purchase_tax_id = taxes
else:
purchase_price = self.env['purchase.pricelist'].search(
[('vendor_id', '=', self.vendor_id.id), ('product_id', '=', self.product_id.id)],
limit=1, order='count_trx_po desc, count_trx_po_vendor desc')
- self.purchase_price = self._get_valid_purchase_price(purchase_price)
- self.purchase_tax_id = 22
+ price, taxes = self._get_valid_purchase_price(purchase_price)
+ self.purchase_price = price
+ self.purchase_tax_id = taxes
def _get_valid_purchase_price(self, purchase_price):
price = 0
+ taxes = ''
human_last_update = purchase_price.human_last_update or datetime.min
system_last_update = purchase_price.system_last_update or datetime.min
+
+ if purchase_price.taxes_product_id.type_tax_use == 'purchase':
+ price = purchase_price.product_price
+ taxes = purchase_price.taxes_product_id.id
if system_last_update > human_last_update:
- price = purchase_price.system_price
- else:
- price = purchase_price.product_price
+ if purchase_price.taxes_system_id.type_tax_use == 'purchase':
+ price = purchase_price.system_price
+ taxes = purchase_price.taxes_system_id.id
- return price or 0
+ return price, taxes
@api.onchange('product_id')
def product_id_change(self):
@@ -148,7 +156,8 @@ class SaleOrderLine(models.Model):
query, limit=1, order='count_trx_po desc, count_trx_po_vendor desc')
line.vendor_id = purchase_price.vendor_id
line.tax_id = line.order_id.sales_tax_id
- line.purchase_price = line._get_valid_purchase_price(purchase_price)
+ price, taxes = line._get_valid_purchase_price(purchase_price)
+ line.purchase_price = price
line_name = ('[' + line.product_id.default_code + ']' if line.product_id.default_code else '') + ' ' + (line.product_id.name if line.product_id.name else '') + ' ' + \
('(' + line.product_id.product_template_attribute_value_ids.name + ')' if line.product_id.product_template_attribute_value_ids.name else '') + ' ' + \
diff --git a/indoteknik_custom/models/shipment_group.py b/indoteknik_custom/models/shipment_group.py
new file mode 100644
index 00000000..92f76db7
--- /dev/null
+++ b/indoteknik_custom/models/shipment_group.py
@@ -0,0 +1,81 @@
+from odoo import models, api, fields
+from odoo.exceptions import AccessError, UserError, ValidationError
+from datetime import timedelta, date
+import logging
+
+_logger = logging.getLogger(__name__)
+
+class ShipmentGroup(models.Model):
+ _name = "shipment.group"
+ _description = "Shipment Group"
+ _inherit = ['mail.thread']
+ _rec_name = 'number'
+
+ number = fields.Char(string='Document No', index=True, copy=False, readonly=True, tracking=True)
+ shipment_line = fields.One2many('shipment.group.line', 'shipment_id', string='Shipment Group Lines', auto_join=True)
+ partner_id = fields.Many2one('res.partner', string='Customer')
+
+ @api.model
+ def create(self, vals):
+ vals['number'] = self.env['ir.sequence'].next_by_code('shipment.group') or '0'
+ result = super(ShipmentGroup, self).create(vals)
+ return result
+
+class ShipmentGroupLine(models.Model):
+ _name = 'shipment.group.line'
+ _description = 'Shipment Group Line'
+ _order = 'shipment_id, id'
+
+ shipment_id = fields.Many2one('shipment.group', string='Shipment Ref', required=True, ondelete='cascade', index=True, copy=False)
+ partner_id = fields.Many2one('res.partner', string='Customer')
+ picking_id = fields.Many2one('stock.picking', string='Picking')
+ sale_id = fields.Many2one('sale.order', string='Sale Order')
+ state = fields.Char(string='Status', readonly=True, compute='_compute_state')
+
+ @api.depends('picking_id.state')
+ def _compute_state(self):
+ for rec in self:
+ if rec.picking_id:
+ if rec.picking_id.state == 'assigned':
+ rec.state = 'Ready'
+ elif rec.picking_id.state == 'done':
+ rec.state = 'Done'
+ elif rec.picking_id.state == 'cancel':
+ rec.state = 'Cancelled'
+ elif rec.picking_id.state == 'confirmed':
+ rec.state = 'Waiting'
+ elif rec.picking_id.state == 'waiting':
+ rec.state = 'Waiting Another Operation'
+ else:
+ rec.state = 'draft'
+ else:
+ rec.state = 'draft'
+
+ @api.onchange('picking_id')
+ def onchange_picking_id(self):
+ if self.picking_id:
+ picking = self.env['stock.picking'].browse(self.picking_id.id)
+
+ if self.shipment_id.partner_id and self.shipment_id.partner_id != picking.partner_id:
+ raise UserError('Partner must be same as shipment group')
+
+ self.partner_id = picking.partner_id
+
+ if not self.shipment_id.partner_id:
+ self.shipment_id.partner_id = picking.partner_id
+
+ self.sale_id = picking.sale_id
+
+ @api.model
+ def create(self, vals):
+ record = super(ShipmentGroupLine, self).create(vals)
+ if record.picking_id:
+ record.onchange_picking_id()
+ return record
+
+ def write(self, vals):
+ res = super(ShipmentGroupLine, self).write(vals)
+ if 'picking_id' in vals:
+ self.onchange_picking_id()
+ return res
+
diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py
index 62d86911..2dd69e01 100644
--- a/indoteknik_custom/models/stock_picking.py
+++ b/indoteknik_custom/models/stock_picking.py
@@ -82,9 +82,12 @@ class StockPicking(models.Model):
('not_printed', 'Belum Print'),
('printed', 'Printed')
], string='Printed?', copy=False, tracking=True)
+ date_printed_sj = fields.Datetime(string='Status Printed Surat Jalan', copy=False, tracking=True)
+ date_printed_list = fields.Datetime(string='Status Printed Picking List', copy=False, tracking=True)
date_unreserve = fields.Datetime(string="Date Unreserved", copy=False, tracking=True)
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')
@api.onchange('carrier_id')
def constrains_carrier_id(self):