diff --git a/addons/product/models/product_supplierinfo.py b/addons/product/models/product_supplierinfo.py
index 5461d0e983e..5545895383e 100644
--- a/addons/product/models/product_supplierinfo.py
+++ b/addons/product/models/product_supplierinfo.py
@@ -62,6 +62,10 @@ class SupplierInfo(models.Model):
delay = fields.Integer(
'Delivery Lead Time', default=1, required=True,
help="Lead time in days between the confirmation of the purchase order and the receipt of the products in your warehouse. Used by the scheduler for automatic computation of the purchase order planning.")
+ discount = fields.Float(
+ string="Discount (%)",
+ digits='Discount',
+ readonly=False)
@api.onchange('product_tmpl_id')
def _onchange_product_tmpl_id(self):
diff --git a/addons/product/views/product_supplierinfo_views.xml b/addons/product/views/product_supplierinfo_views.xml
index e5eea2d7e56..d97d7027ac7 100644
--- a/addons/product/views/product_supplierinfo_views.xml
+++ b/addons/product/views/product_supplierinfo_views.xml
@@ -32,6 +32,7 @@
to
+
@@ -117,6 +118,7 @@
+
diff --git a/addons/purchase/models/purchase.py b/addons/purchase/models/purchase.py
index d69d16f4284..7ffc0d0c2f7 100644
--- a/addons/purchase/models/purchase.py
+++ b/addons/purchase/models/purchase.py
@@ -509,6 +509,7 @@ class PurchaseOrder(models.Model):
'min_qty': 1.0,
'price': price,
'currency_id': currency.id,
+ 'discount': line.discount,
'delay': 0,
}
@@ -926,6 +927,11 @@ class PurchaseOrderLine(models.Model):
string='Expected Arrival', index=True,
compute="_compute_price_unit_and_date_planned_and_name", readonly=False, store=True,
help="Delivery date expected from vendor. This date respectively defaults to vendor pricelist lead time then today's date.")
+ discount = fields.Float(
+ string="Discount (%)",
+ compute='_compute_price_unit_and_date_planned_and_name',
+ digits='Discount',
+ store=True, readonly=False)
taxes_id = fields.Many2many('account.tax', string='Taxes', domain=['|', ('active', '=', False), ('active', '=', True)])
product_uom = fields.Many2one('uom.uom', string='Unit of Measure', domain="[('category_id', '=', product_uom_category_id)]")
product_uom_category_id = fields.Many2one(related='product_id.uom_id.category_id')
@@ -981,7 +987,7 @@ class PurchaseOrderLine(models.Model):
"Forbidden values on non-accountable purchase order line"),
]
- @api.depends('product_qty', 'price_unit', 'taxes_id')
+ @api.depends('product_qty', 'price_unit', 'taxes_id', 'discount')
def _compute_amount(self):
for line in self:
tax_results = self.env['account.tax']._compute_taxes([line._convert_to_tax_base_line_dict()])
@@ -1010,6 +1016,7 @@ class PurchaseOrderLine(models.Model):
taxes=self.taxes_id,
price_unit=self.price_unit,
quantity=self.product_qty,
+ discount=self.discount,
price_subtotal=self.price_subtotal,
)
@@ -1249,6 +1256,7 @@ class PurchaseOrderLine(models.Model):
price_unit = seller.currency_id._convert(price_unit, line.currency_id, line.company_id, line.date_order or fields.Date.context_today(line), False)
price_unit = float_round(price_unit, precision_digits=max(line.currency_id.decimal_places, self.env['decimal.precision'].precision_get('Product Price')))
line.price_unit = seller.product_uom._compute_price(price_unit, line.product_uom)
+ line.discount = seller.discount or 0.0
# record product names to avoid resetting custom descriptions
default_names = []
@@ -1319,6 +1327,8 @@ class PurchaseOrderLine(models.Model):
def _get_gross_price_unit(self):
self.ensure_one()
price_unit = self.price_unit
+ if self.discount:
+ price_unit = price_unit * (1 - self.discount / 100)
if self.taxes_id:
qty = self.product_qty or 1
price_unit_prec = self.env['decimal.precision'].precision_get('Product Price')
@@ -1372,6 +1382,7 @@ class PurchaseOrderLine(models.Model):
'product_id': self.product_id.id,
'product_uom_id': self.product_uom.id,
'quantity': self.qty_to_invoice,
+ 'discount': self.discount,
'price_unit': self.currency_id._convert(self.price_unit, aml_currency, self.company_id, date, round=False),
'tax_ids': [(6, 0, self.taxes_id.ids)],
'purchase_line_id': self.id,
diff --git a/addons/purchase/tests/test_purchase.py b/addons/purchase/tests/test_purchase.py
index 1977e2423bf..83afaf94583 100644
--- a/addons/purchase/tests/test_purchase.py
+++ b/addons/purchase/tests/test_purchase.py
@@ -418,3 +418,44 @@ class TestPurchase(AccountTestInvoicingCommon):
product._invalidate_cache()
self.assertEqual(product.seller_ids[0].partner_id, self.partner_a)
self.assertEqual(product.seller_ids[0].company_id, company_a)
+
+ def test_discount_po_line_vendorpricelist(self):
+ """ Set a discount in VendorPriceList and check if that discount comes in po line and if vendor select
+ a product which is not present in vendorPriceList then it should be created.
+ """
+ po = Form(self.env['purchase.order'])
+ po.partner_id = self.partner_a
+ with po.order_line.new() as po_line:
+ po_line.product_id = self.product_a
+ po_line.product_qty = 1
+ po_line.price_unit = 100
+ po_line.discount = 20
+ po = po.save()
+ po.button_confirm()
+
+ supplierinfo_id = self.env['product.supplierinfo'].search([
+ ('partner_id', '=', self.partner_a.id),
+ ('product_tmpl_id', '=', self.product_a.product_tmpl_id.id),
+ ], limit=1)
+
+ self.assertTrue(supplierinfo_id)
+ self.assertEqual(supplierinfo_id.discount, 20)
+
+ # checking the same discount
+ self.env['product.supplierinfo'].create({
+ 'partner_id': self.partner_b.id,
+ 'product_tmpl_id': self.product_a.product_tmpl_id.id,
+ 'min_qty': 1,
+ 'price': 100,
+ 'discount': 30,
+ })
+
+ po1 = Form(self.env['purchase.order'])
+ po1.partner_id = self.partner_b
+ with po1.order_line.new() as po_line:
+ po_line.product_id = self.product_a
+ po_line.product_qty = 1
+ po1 = po1.save()
+
+ self.assertEqual(po1.order_line[0].price_unit, 100)
+ self.assertEqual(po1.order_line[0].discount, 30)
diff --git a/addons/purchase/views/purchase_views.xml b/addons/purchase/views/purchase_views.xml
index 001c03eee1d..b3a31ada885 100644
--- a/addons/purchase/views/purchase_views.xml
+++ b/addons/purchase/views/purchase_views.xml
@@ -257,6 +257,7 @@
+