summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAzka Nathan <darizkyfaz@gmail.com>2024-10-03 10:12:24 +0700
committerAzka Nathan <darizkyfaz@gmail.com>2024-10-03 10:12:24 +0700
commit4a69c71eab2d4ea3504a0cf6e3a9ca241be48594 (patch)
treeeb03e833a86acfe72870099d1671ad6dfae86d37
parent8b63d79efe0137ce6af535847f33868e73ce8d3c (diff)
push
-rwxr-xr-xindoteknik_custom/models/sale_order.py32
-rw-r--r--indoteknik_custom/models/sale_order_line.py7
-rw-r--r--indoteknik_custom/models/vendor_approval.py39
-rwxr-xr-xindoteknik_custom/views/sale_order.xml2
4 files changed, 77 insertions, 3 deletions
diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py
index f8127d8c..538e0209 100755
--- a/indoteknik_custom/models/sale_order.py
+++ b/indoteknik_custom/models/sale_order.py
@@ -145,9 +145,8 @@ class SaleOrder(models.Model):
missing_weight_products.append(line.product_id.name)
if missing_weight_products:
- product_names = '\n'.join(missing_weight_products)
- self.message_post(body=f"Produk berikut tidak memiliki berat: \n{product_names}")
-
+ product_names = '<br/>'.join(missing_weight_products)
+ self.message_post(body=f"Produk berikut tidak memiliki berat:<br/>{product_names}")
if total_weight == 0:
raise UserError("Tidak dapat mengestimasi ongkir tanpa berat yang valid.")
@@ -802,9 +801,36 @@ class SaleOrder(models.Model):
'body_html': email_body,
'email_to': salesperson_email,
}).send()
+
+ def validate_different_vendor(self):
+ different_vendor = self.order_line.filtered(lambda l: l.vendor_id.id != l.vendor_md_id.id)
+ if different_vendor:
+ vendor_approval = self.env['vendor.approval'].create({
+ 'order_id': self.id,
+ 'state': 'draft',
+ })
+ for line in self.line:
+ self.env['vendor.approval.line'].create({
+ 'vendor_approval_id': vendor_approval.id,
+ 'product_id': line.product_id.id,
+ 'product_uom_qty': line.product_uom_qty,
+ 'vendor_id': line.vendor_id.id,
+ 'vendor_md_id': line.vendor_md_id.id,
+ 'purchase_price': line.purchase_price,
+ 'purchase_price_md': line.purchase_price_md,
+ })
+
+ return True
+ else:
+ return False
+
+
def action_confirm(self):
for order in self:
+ if order.validate_partner_invoice_due():
+ return self._create_notification_action('Notification', 'Terdapat Vendor yang berbeda dengan MD Vendor')
+
order.check_data_real_delivery_address()
order.sale_order_check_approve()
order._validate_order()
diff --git a/indoteknik_custom/models/sale_order_line.py b/indoteknik_custom/models/sale_order_line.py
index d1dcd0af..dca8534c 100644
--- a/indoteknik_custom/models/sale_order_line.py
+++ b/indoteknik_custom/models/sale_order_line.py
@@ -14,7 +14,12 @@ class SaleOrderLine(models.Model):
states={'draft': [('readonly', False)], 'sent': [('readonly', False)]},
domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]"
)
+ vendor_md_id = fields.Many2one(
+ 'res.partner', string='MD Vendor', readonly=True,
+ change_default=True, index=True, tracking=1
+ )
purchase_price = fields.Float('Purchase', required=True, digits='Product Price', default=0.0)
+ purchase_price_md = fields.Float('MD Purchase', required=True, digits='Product Price', default=0.0)
purchase_tax_id = fields.Many2one('account.tax', string='Tax', domain=['|', ('active', '=', False), ('active', '=', True)])
delivery_amt_line = fields.Float('DeliveryAmtLine', compute='compute_delivery_amt_line')
fee_third_party_line = fields.Float('FeeThirdPartyLine', compute='compute_fee_third_party_line', default=0)
@@ -245,9 +250,11 @@ class SaleOrderLine(models.Model):
# query, limit=1, order='count_trx_po desc, count_trx_po_vendor desc')
price, taxes, vendor_id = self._get_purchase_price(line.product_id)
line.vendor_id = vendor_id
+ line.vendor_md_id = vendor_id
line.tax_id = line.order_id.sales_tax_id
# price, taxes = line._get_valid_purchase_price(purchase_price)
line.purchase_price = price
+ line.purchase_price_md = price
line.purchase_tax_id = taxes
attribute_values = line.product_id.product_template_attribute_value_ids.mapped('name')
diff --git a/indoteknik_custom/models/vendor_approval.py b/indoteknik_custom/models/vendor_approval.py
new file mode 100644
index 00000000..4369a193
--- /dev/null
+++ b/indoteknik_custom/models/vendor_approval.py
@@ -0,0 +1,39 @@
+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 VendorApproval(models.Model):
+ _name = "vendor.approval"
+ _description = "Vendor Approval"
+ _inherit = ['mail.thread']
+ _rec_name = 'number'
+
+ number = fields.Char(string='Document No', index=True, copy=False, readonly=True, tracking=True)
+ partner_id = fields.Many2one('res.partner', string="Customer", readonly=True)
+ order_id = fields.Many2one('sale.order', string="SO", readonly=True)
+ vendor_approval_line = fields.One2many('vendor.approval.line', 'vendor_approval_id', string='Vendor Approval Lines', auto_join=True)
+
+ def unlink(self):
+ res = super(VendorApproval, self).unlink()
+ if not self._name == 'vendor.approval':
+ raise UserError('Vendor Approval tidak bisa didelete')
+ return res
+
+
+class VendorApprovalLine(models.Model):
+ _name = 'vendor.approval.line'
+ _description = 'Vendor Approval Line'
+ _order = 'vendor_approval_id, id'
+
+ vendor_approval_id = fields.Many2one('vendor.approval', string='Vendor Approval Ref', required=True, ondelete='cascade', index=True, copy=False)
+ product_id = fields.Many2one('product.product', string='Product')
+ product_uom_qty = fields.Float(string='Quantity')
+ vendor_id = fields.Many2one('res.partner', string='Vendor')
+ vendor_md_id = fields.Many2one('res.partner', string='Vendor MD')
+ purchase_price = fields.Many2one(string='Purchase Price')
+ purchase_price_md= fields.Many2one(string='Purchase Price MD')
+
+
diff --git a/indoteknik_custom/views/sale_order.xml b/indoteknik_custom/views/sale_order.xml
index 029c99e9..f2a57fc7 100755
--- a/indoteknik_custom/views/sale_order.xml
+++ b/indoteknik_custom/views/sale_order.xml
@@ -117,6 +117,7 @@
</xpath>
<xpath expr="//form/sheet/notebook/page/field[@name='order_line']/tree/field[@name='price_total']" position="after">
<field name="vendor_id" attrs="{'readonly': [('parent.approval_status', '=', 'approved')]}" domain="[('parent_id', '=', False)]" options="{'no_create':True}"/>
+ <field name="vendor_md_id" readonly="1" options="{'no_create':True}"/>
<field name="purchase_price" attrs="
{
'readonly': [
@@ -126,6 +127,7 @@
]
}
"/>
+ <field name="purchase_price_md" readonly="1"/>
<field name="purchase_tax_id" attrs="{'readonly': [('parent.approval_status', '!=', False)]}" domain="[('type_tax_use','=','purchase')]" options="{'no_create':True}"/>
<field name="item_percent_margin"/>
<field name="item_margin" optional="hide"/>