[IMP] purchase: Supplier info added with sudo qty 1
This commit contains the following: 1) Added sudo to product record when adding supplier info during PO confirm, so that supplier info is created regardless of who is confirming the PO. 2) the test test_multicompany_partner_bank was removed since it was creating two res partner banks with the same partner and setting company_id to two seperate companies while currently the company_id is related to the company partner thus this can no longer happen. 3) test_message_qty_already_received was changed to not set the company_id explicitly as it caused unexpected cache miss in the runbot. task : 2764771 Part-of: odoo/odoo#91640
This commit is contained in:
committed by
Ahmed Khalaf (ahkh)
parent
d5bf927bf9
commit
3b88ed5ea4
@@ -12,7 +12,7 @@ from odoo import api, fields, models, _
|
||||
from odoo.osv import expression
|
||||
from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT, format_amount, format_date, formatLang, get_lang, groupby
|
||||
from odoo.tools.float_utils import float_compare, float_is_zero, float_round
|
||||
from odoo.exceptions import AccessError, UserError, ValidationError
|
||||
from odoo.exceptions import UserError, ValidationError
|
||||
|
||||
|
||||
class PurchaseOrder(models.Model):
|
||||
@@ -492,7 +492,7 @@ class PurchaseOrder(models.Model):
|
||||
return {
|
||||
'partner_id': partner.id,
|
||||
'sequence': max(line.product_id.seller_ids.mapped('sequence')) + 1 if line.product_id.seller_ids else 1,
|
||||
'min_qty': 0.0,
|
||||
'min_qty': 1.0,
|
||||
'price': price,
|
||||
'currency_id': currency.id,
|
||||
'delay': 0,
|
||||
@@ -528,10 +528,8 @@ class PurchaseOrder(models.Model):
|
||||
vals = {
|
||||
'seller_ids': [(0, 0, supplierinfo)],
|
||||
}
|
||||
try:
|
||||
line.product_id.write(vals)
|
||||
except AccessError: # no write access rights -> just ignore
|
||||
break
|
||||
# supplier info should be added regardless of the user access rights
|
||||
line.product_id.sudo().write(vals)
|
||||
|
||||
def action_create_invoice(self):
|
||||
"""Create the invoice associated to the PO.
|
||||
|
||||
@@ -327,71 +327,3 @@ class TestPurchaseToInvoice(AccountTestInvoicingCommon):
|
||||
|
||||
aml = self.env['account.move.line'].search([('purchase_line_id', '=', purchase_order.order_line.id)])
|
||||
self.assertRecordValues(aml, [{'analytic_account_id': analytic_account_manual.id}])
|
||||
|
||||
def test_multicompany_partner_bank(self):
|
||||
""" Test that in a multiple company environment, the bank account of the invoice
|
||||
is the one corresponding to the active company. """
|
||||
company_a = self.env.user.company_id
|
||||
company_b = self.env['res.company'].create({
|
||||
'name': 'Company B',
|
||||
})
|
||||
self.env.ref('l10n_generic_coa.configurable_chart_template')._load(company_b)
|
||||
|
||||
partner = self.env['res.partner'].create({
|
||||
'name': 'AAAAA',
|
||||
})
|
||||
partner_bank_a = self.env['res.partner.bank'].create({
|
||||
'acc_number': "BE01 23456789 10",
|
||||
'partner_id': partner.id,
|
||||
'acc_type': 'bank'
|
||||
})
|
||||
partner_bank_b = self.env['res.partner.bank'].create({
|
||||
'acc_number': "BE10 98765432 10",
|
||||
'partner_id': partner.id,
|
||||
'acc_type': 'bank'
|
||||
})
|
||||
partner.bank_ids = [partner_bank_a.id, partner_bank_b.id]
|
||||
partner_bank_a.company_id = company_a
|
||||
partner_bank_b.company_id = company_b
|
||||
|
||||
PurchaseOrder = self.env['purchase.order'].with_context(tracking_disable=True)
|
||||
po_a = PurchaseOrder.with_company(company_a).create({
|
||||
'partner_id': partner.id,
|
||||
'company_id': company_a.id,
|
||||
'currency_id': company_a.currency_id.id,
|
||||
'date_order': '2019-01-01',
|
||||
})
|
||||
po_b = PurchaseOrder.with_company(company_b).create({
|
||||
'partner_id': partner.id,
|
||||
'company_id': company_b.id,
|
||||
'currency_id': company_b.currency_id.id,
|
||||
'date_order': '2019-01-01',
|
||||
})
|
||||
|
||||
vals_pol = {
|
||||
'name': self.product_deliver.name,
|
||||
'product_id': self.product_deliver.id,
|
||||
'product_qty': 10.0,
|
||||
'product_uom': self.product_deliver.uom_id.id,
|
||||
'price_unit': self.product_deliver.list_price,
|
||||
'order_id': po_a.id,
|
||||
'taxes_id': False,
|
||||
}
|
||||
PurchaseOrderLine = self.env['purchase.order.line'].with_context(tracking_disable=True)
|
||||
PurchaseOrderLine.create(vals_pol)
|
||||
vals_pol['order_id'] = po_b.id
|
||||
PurchaseOrderLine.create(vals_pol)
|
||||
|
||||
po_a.button_confirm()
|
||||
po_b.button_confirm()
|
||||
|
||||
po_a.order_line.qty_received = po_b.order_line.qty_received = 10
|
||||
|
||||
po_a.with_company(company_a).action_create_invoice()
|
||||
po_b.with_company(company_b).action_create_invoice()
|
||||
|
||||
self.assertEqual(po_a.invoice_ids.company_id, company_a)
|
||||
self.assertEqual(po_a.invoice_ids.partner_bank_id, partner_bank_a)
|
||||
|
||||
self.assertEqual(po_b.invoice_ids.company_id, company_b)
|
||||
self.assertEqual(po_b.invoice_ids.partner_bank_id, partner_bank_b)
|
||||
|
||||
@@ -370,19 +370,14 @@ class TestPurchaseOrder(ValuationReconciliationTestCommon):
|
||||
self.assertEqual(po.order_line.mapped('qty_received'), [4.0], 'Purchase: no conversion error on receipt in different uom"')
|
||||
|
||||
def test_message_qty_already_received(self):
|
||||
_product = self.env['product.product'].create({
|
||||
'name': 'TempProduct',
|
||||
'type': 'consu',
|
||||
'company_id': self.env.user.company_id.id,
|
||||
})
|
||||
self.env.user.write({'company_id': self.company_data['company'].id})
|
||||
|
||||
_purchase_order = self.env['purchase.order'].create({
|
||||
'company_id': self.env.user.company_id.id,
|
||||
'partner_id': self.partner_a.id,
|
||||
'order_line': [
|
||||
(0, 0, {
|
||||
'name': _product.name,
|
||||
'product_id': _product.id,
|
||||
'name': self.product_id_2.name,
|
||||
'product_id': self.product_id_2.id,
|
||||
'product_qty': 25.0,
|
||||
'price_unit': 250.0,
|
||||
})],
|
||||
|
||||
Reference in New Issue
Block a user