summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--indoteknik_custom/models/automatic_purchase.py18
-rw-r--r--indoteknik_custom/views/automatic_purchase.xml3
2 files changed, 18 insertions, 3 deletions
diff --git a/indoteknik_custom/models/automatic_purchase.py b/indoteknik_custom/models/automatic_purchase.py
index 97f77070..e28f71f5 100644
--- a/indoteknik_custom/models/automatic_purchase.py
+++ b/indoteknik_custom/models/automatic_purchase.py
@@ -8,6 +8,7 @@ _logger = logging.getLogger(__name__)
class AutomaticPurchase(models.Model):
_name = 'automatic.purchase'
+ _order = 'id desc'
date_doc = fields.Date(string='Date', required=True, help='Isi tanggal hari ini')
description = fields.Char(string='Description', help='bebas isi nya apa')
@@ -15,6 +16,7 @@ class AutomaticPurchase(models.Model):
notification = fields.Char(string='Notification')
is_po = fields.Boolean(string='Is PO')
purchase_match = fields.One2many('automatic.purchase.match', 'automatic_purchase_id', string='Matches', auto_join=True)
+ vendor_id = fields.Many2one('res.partner', string='Vendor', help='boleh kosong, jika diisi, maka hanya keluar data untuk vendor tersebut')
def create_po_from_automatic_purchase(self):
if not self.purchase_lines:
@@ -77,9 +79,17 @@ class AutomaticPurchase(models.Model):
continue
qty_purchase = point.product_max_qty - point.product_id.qty_available
po_line = self.env['purchase.order.line'].search([('product_id', '=', point.product_id.id), ('order_id.state', '=', 'done')], limit=1)
- purchase_price = self.env['purchase.pricelist'].search([('product_id', '=', point.product_id.id)], order='product_price asc', limit=1)
+
+ if self.vendor_id:
+ purchase_price = self.env['purchase.pricelist'].search([
+ ('product_id', '=', point.product_id.id),
+ ('vendor_id', '=', self.vendor_id.id)
+ ], order='product_price asc', limit=1)
+ else:
+ purchase_price = self.env['purchase.pricelist'].search([('product_id', '=', point.product_id.id)], order='product_price asc', limit=1)
+
vendor_id = purchase_price.vendor_id.id
- price = purchase_price.product_price
+ price = purchase_price.product_price or 0
self.env['automatic.purchase.line'].create([{
'automatic_purchase_id': self.id,
@@ -94,7 +104,8 @@ class AutomaticPurchase(models.Model):
'last_price': price,
'subtotal': qty_purchase * price,
'last_order_id': po_line.order_id.id,
- 'last_orderline_id': po_line.id
+ 'last_orderline_id': po_line.id,
+ 'brand_id': point.product_id.product_tmpl_id.x_manufacture.id
}])
count += 1
_logger.info('Create Automatic Purchase Line %s' % point.product_id.name)
@@ -120,6 +131,7 @@ class AutomaticPurchaseLine(models.Model):
is_po = fields.Boolean(String='Is PO')
current_po_id = fields.Many2one('purchase.order', string='Current')
current_po_line_id = fields.Many2one('purchase.order.line', string='Current Line')
+ brand_id = fields.Many2one('x_manufactures', string='Brand')
class AutomaticPurchaseMatch(models.Model):
diff --git a/indoteknik_custom/views/automatic_purchase.xml b/indoteknik_custom/views/automatic_purchase.xml
index 8873c58a..49751f4e 100644
--- a/indoteknik_custom/views/automatic_purchase.xml
+++ b/indoteknik_custom/views/automatic_purchase.xml
@@ -6,6 +6,7 @@
<field name="arch" type="xml">
<tree>
<field name="date_doc"/>
+ <field name="vendor_id"/>
<field name="description"/>
<field name="notification" readonly="1"/>
<field name="is_po" readonly="1"/>
@@ -18,6 +19,7 @@
<field name="model">automatic.purchase.line</field>
<field name="arch" type="xml">
<tree>
+ <field name="brand_id"/>
<field name="product_id"/>
<field name="qty_purchase"/>
<field name="qty_min"/>
@@ -54,6 +56,7 @@
<group>
<group>
<field name="date_doc"/>
+ <field name="vendor_id"/>
<field name="description"/>
<field name="notification" readonly="1"/>
</group>