[IMP] purchase: added discount field in Vendor Pricelist
In this commit ============== - Added the discount fields to the vendor pricelist and PO line models, making them optional and hidden. - Implemented automatic filling of the discount field on the PO line when the unit price is sourced from the vendor pricelist. - Implemented a mechanism to automatically populate the discount field on the PO line when the unit price is fetched from the vendor pricelist. - Modified the pricing logic to ensure the discount is applied to the tax-excluded price. - PO confirmation process to check if a pricelist already exists for the vendor. If not, a new pricelist line is created, including the discount if it is present. task - 3380306 closes odoo/odoo#126804 Signed-off-by: Arnold Moyaux (arm) <arm@odoo.com>
This commit is contained in:
committed by
Arnold Moyaux
parent
9dc0777d0f
commit
af0d1b565c
@@ -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):
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
</div>
|
||||
<label for="date_start" string="Validity"/>
|
||||
<div class="o_row"><field name="date_start" class="oe_inline"/> to <field name="date_end" class="oe_inline"/></div>
|
||||
<field name="discount"/>
|
||||
<field name="company_id" options="{'no_create': True}"/>
|
||||
</group>
|
||||
</group>
|
||||
@@ -117,6 +118,7 @@
|
||||
<field name="min_qty" optional="hide"/>
|
||||
<field name="product_uom" groups="uom.group_uom" optional="hide"/>
|
||||
<field name="price" string="Price"/>
|
||||
<field name="discount" optional="hide"/>
|
||||
<field name="currency_id" groups="base.group_multi_currency"/>
|
||||
<field name="delay" optional="hide"/>
|
||||
</tree>
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -257,6 +257,7 @@
|
||||
<field name="price_unit" readonly="qty_invoiced != 0"/>
|
||||
<button name="action_purchase_history" type="object" icon="fa-history" title="Purchase History" invisible="not id"/>
|
||||
<field name="taxes_id" widget="many2many_tags" domain="[('type_tax_use','=','purchase'), ('company_id', '=', parent.company_id), ('country_id', '=', parent.tax_country_id)]" context="{'default_type_tax_use': 'purchase', 'search_view_ref': 'account.account_tax_view_search'}" options="{'no_create': True}" optional="show"/>
|
||||
<field name="discount" string="Disc.%" readonly="qty_invoiced != 0" optional="hide"/>
|
||||
<field name="price_subtotal" string="Tax excl."/>
|
||||
<field name="price_total"
|
||||
string="Tax incl."
|
||||
|
||||
Reference in New Issue
Block a user