[IMP] purchase_stock: day to purchase
Create RFQ with an order by date in futur. It will allow to discuss RFQ before validate them and to be in time for the need. today Order by Sheduled date of receipt |_______________|___________________|_____________________| days to purchase vendor LT security days Task: 1849912
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
from . import account_invoice
|
||||
from . import product
|
||||
from . import purchase
|
||||
from . import res_company
|
||||
from . import res_config_settings
|
||||
from . import stock
|
||||
from . import stock_rule
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class ResCompany(models.Model):
|
||||
_inherit = 'res.company'
|
||||
|
||||
days_to_purchase = fields.Float(
|
||||
string='Days to Purchase',
|
||||
help="Days needed to confirm a PO, define when a PO should be validated")
|
||||
@@ -8,6 +8,8 @@ class ResConfigSettings(models.TransientModel):
|
||||
_inherit = 'res.config.settings'
|
||||
|
||||
module_stock_dropshipping = fields.Boolean("Dropshipping")
|
||||
days_to_purchase = fields.Float(
|
||||
related='company_id.days_to_purchase', readonly=False)
|
||||
|
||||
is_installed_sale = fields.Boolean(string="Is the Sale Module Installed")
|
||||
|
||||
|
||||
@@ -144,7 +144,9 @@ class StockRule(models.Model):
|
||||
delay_description += '<tr><td>%s</td><td>+ %d %s</td></tr>' % (_('Vendor Lead Time'), supplier_delay, _('day(s)'))
|
||||
security_delay = buy_rule.picking_type_id.company_id.po_lead
|
||||
delay_description += '<tr><td>%s</td><td>+ %d %s</td></tr>' % (_('Purchase Security Lead Time'), security_delay, _('day(s)'))
|
||||
return delay + supplier_delay + security_delay, delay_description
|
||||
days_to_purchase = buy_rule.company_id.days_to_purchase
|
||||
delay_description += '<tr><td>%s</td><td>+ %d %s</td></tr>' % (_('Days to Purchase'), days_to_purchase, _('day(s)'))
|
||||
return delay + supplier_delay + security_delay + days_to_purchase, delay_description
|
||||
|
||||
@api.model
|
||||
def _get_procurements_to_merge_groupby(self, procurement):
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from datetime import timedelta
|
||||
from datetime import datetime, timedelta
|
||||
from unittest.mock import patch
|
||||
|
||||
from odoo import fields
|
||||
from .common import PurchaseTestCommon
|
||||
from odoo.tests.common import Form
|
||||
|
||||
|
||||
class TestPurchaseLeadTime(PurchaseTestCommon):
|
||||
@@ -239,3 +241,56 @@ class TestPurchaseLeadTime(PurchaseTestCommon):
|
||||
self.assertEqual(len(po_line), 2, 'the purchase order lines are merged')
|
||||
self.assertEqual(po_line[0].product_qty, 10, 'the purchase order line has a wrong quantity')
|
||||
self.assertEqual(po_line[1].product_qty, 5, 'the purchase order line has a wrong quantity')
|
||||
|
||||
def test_reordering_days_to_purchase(self):
|
||||
self.patcher = patch('odoo.addons.stock.models.stock_orderpoint.fields.Date', wraps=fields.Date)
|
||||
self.mock_date = self.patcher.start()
|
||||
|
||||
vendor = self.env['res.partner'].create({
|
||||
'name': 'Colruyt'
|
||||
})
|
||||
|
||||
self.env.company.days_to_purchase = 2.0
|
||||
|
||||
product = self.env['product.product'].create({
|
||||
'name': 'Chicory',
|
||||
'type': 'product',
|
||||
'seller_ids': [(0, 0, {'name': vendor.id, 'delay': 1.0})]
|
||||
})
|
||||
orderpoint_form = Form(self.env['stock.warehouse.orderpoint'])
|
||||
orderpoint_form.product_id = product
|
||||
orderpoint_form.product_min_qty = 0.0
|
||||
orderpoint = orderpoint_form.save()
|
||||
|
||||
warehouse = self.env['stock.warehouse'].search([], limit=1)
|
||||
delivery_moves = self.env['stock.move']
|
||||
for i in range(0, 6):
|
||||
delivery_moves |= self.env['stock.move'].create({
|
||||
'name': 'Delivery',
|
||||
'date_expected': datetime.today() + timedelta(days=i),
|
||||
'product_id': product.id,
|
||||
'product_uom': product.uom_id.id,
|
||||
'product_uom_qty': 5.0,
|
||||
'location_id': warehouse.lot_stock_id.id,
|
||||
'location_dest_id': self.ref('stock.stock_location_customers'),
|
||||
})
|
||||
delivery_moves._action_confirm()
|
||||
self.env['procurement.group'].run_scheduler()
|
||||
po_line = self.env['purchase.order.line'].search([('product_id', '=', product.id)])
|
||||
self.assertEqual(fields.Date.to_date(po_line.order_id.date_order), fields.Date.today() + timedelta(days=2))
|
||||
self.assertEqual(len(po_line), 1)
|
||||
self.assertEqual(po_line.product_uom_qty, 20.0)
|
||||
self.assertEqual(len(po_line.order_id), 1)
|
||||
orderpoint_form = Form(orderpoint)
|
||||
orderpoint_form.save()
|
||||
|
||||
self.mock_date.today.return_value = fields.Date.today() + timedelta(days=1)
|
||||
self.env.cache.invalidate()
|
||||
self.env['procurement.group'].run_scheduler()
|
||||
po_line = self.env['purchase.order.line'].search([('product_id', '=', product.id)])
|
||||
self.assertEqual(len(po_line), 2)
|
||||
self.assertEqual(len(po_line.order_id), 2)
|
||||
new_order = po_line.order_id.sorted('date_order')[-1]
|
||||
self.assertEqual(fields.Date.to_date(new_order.date_order), fields.Date.today() + timedelta(days=2))
|
||||
self.assertEqual(new_order.order_line.product_uom_qty, 5.0)
|
||||
self.patcher.stop()
|
||||
|
||||
@@ -55,6 +55,20 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-12 col-lg-6 o_setting_box">
|
||||
<div class="o_setting_right_pane">
|
||||
<label for="days_to_purchase"/>
|
||||
<span class="fa fa-lg fa-building-o" title="Values set here are company-specific." aria-label="Values set here are company-specific." groups="base.group_multi_company"/>
|
||||
<div class="text-muted">
|
||||
Days needed to confirm a PO, define when a PO should be validated
|
||||
</div>
|
||||
<div class="content-group">
|
||||
<div class="mt16">
|
||||
<span><field name="days_to_purchase" class="oe_inline"/> days</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
Reference in New Issue
Block a user