[PATCH] Upstream patch - 19092023

This commit is contained in:
Parthiv Patel
2023-09-19 08:34:27 +00:00
parent 195e53e1f5
commit c011a4f5d3
6 changed files with 44 additions and 25 deletions
+11 -1
View File
@@ -2,6 +2,7 @@
import datetime
import json
import logging
import os
import random
import select
import threading
@@ -12,11 +13,16 @@ from flectra import api, fields, models, SUPERUSER_ID
from flectra.tools.misc import DEFAULT_SERVER_DATETIME_FORMAT
from flectra.tools import date_utils
from psycopg2 import sql
_logger = logging.getLogger(__name__)
# longpolling timeout connection
TIMEOUT = 50
# custom function to call instead of NOTIFY postgresql command (opt-in)
FLECTRA_NOTIFY_FUNCTION = os.environ.get('FLECTRA_NOTIFY_FUNCTION')
#----------------------------------------------------------
# Bus
#----------------------------------------------------------
@@ -62,7 +68,11 @@ class ImBus(models.Model):
@self.env.cr.postcommit.add
def notify():
with flectra.sql_db.db_connect('postgres').cursor() as cr:
cr.execute("notify imbus, %s", (json_dump(list(channels)),))
if FLECTRA_NOTIFY_FUNCTION:
query = sql.SQL("SELECT {}('imbus', %s)").format(sql.Identifier(FLECTRA_NOTIFY_FUNCTION))
else:
query = "NOTIFY imbus, %s"
cr.execute(query, (json_dump(list(channels)), ))
@api.model
def sendone(self, channel, message):
+9
View File
@@ -8,6 +8,15 @@ from flectra import models, api, _
class AccountChartTemplate(models.Model):
_inherit = "account.chart.template"
def _load(self, sale_tax_rate, purchase_tax_rate, company):
res = super()._load(sale_tax_rate, purchase_tax_rate, company)
if company.chart_template_id == self.env.ref('l10n_mx.mx_coa'):
company.write({
'account_sale_tax_id': self.env.ref(f'l10n_mx.{company.id}_tax12'),
'account_purchase_tax_id': self.env.ref(f'l10n_mx.{company.id}_tax14'),
})
return res
@api.model
def generate_journals(self, acc_template_ref, company, journals_dict=None):
"""Set the tax_cash_basis_journal_id on the company"""
@@ -92,7 +92,7 @@ class TestPoSProductsWithTax(TestPoSCommon):
# check values before closing the session
self.assertEqual(3, self.pos_session.order_count)
orders_total = sum(order.amount_total for order in self.pos_session.order_ids)
self.assertAlmostEqual(orders_total, self.pos_session.total_payments_amount, 'Total order amount should be equal to the total payment amount.')
self.assertAlmostEqual(orders_total, self.pos_session.total_payments_amount, msg='Total order amount should be equal to the total payment amount.')
# close the session
self.pos_session.action_pos_session_validate()
@@ -329,7 +329,7 @@ class TestValuationReconciliation(ValuationReconciliationTestCommon):
exchange_move = valuation_line.full_reconcile_id.exchange_move_id
self.assertTrue(exchange_move, "An exchange move should exists.")
exchange_difference = exchange_move.line_ids.filtered(lambda l: l.account_id.id == interim_account_id).balance
self.assertAlmostEqual(exchange_difference, 38.46, "Exchange amount is incorrect")
self.assertAlmostEqual(exchange_difference, 38.46, msg="Exchange amount is incorrect")
def test_reconcile_cash_basis_bill(self):
''' Test the generation of the CABA move after bill payment
@@ -479,16 +479,16 @@ class TestStockValuationWithCOA(AccountTestInvoicingCommon):
# Check what was posted in the price difference account
price_diff_aml = self.env['account.move.line'].search([('account_id','=', self.price_diff_account.id)])
self.assertEqual(len(price_diff_aml), 1, "Only one line should have been generated in the price difference account.")
self.assertAlmostEqual(price_diff_aml.debit, 5, "Price difference should be equal to 5 (15-10)")
self.assertAlmostEqual(price_diff_aml.debit, 5, msg="Price difference should be equal to 5 (15-10)")
# Check what was posted in stock input account
input_aml = self.env['account.move.line'].search([('account_id','=',self.stock_input_account.id)])
self.assertEqual(len(input_aml), 3, "Only three lines should have been generated in stock input account: one when receiving the product, one when making the invoice.")
invoice_amls = input_aml.filtered(lambda l: l.move_id == invoice)
picking_aml = input_aml - invoice_amls
self.assertAlmostEqual(sum(invoice_amls.mapped('debit')), 15, "Total debit value on stock input account should be equal to the original PO price of the product.")
self.assertAlmostEqual(sum(invoice_amls.mapped('credit')), 5, "Total debit value on stock input account should be equal to the original PO price of the product.")
self.assertAlmostEqual(sum(picking_aml.mapped('credit')), 10, "Total credit value on stock input account should be equal to the original PO price of the product.")
self.assertAlmostEqual(sum(invoice_amls.mapped('debit')), 15, msg="Total debit value on stock input account should be equal to the original PO price of the product.")
self.assertAlmostEqual(sum(invoice_amls.mapped('credit')), 5, msg="Total debit value on stock input account should be equal to the original PO price of the product.")
self.assertAlmostEqual(sum(picking_aml.mapped('credit')), 10, msg="Total credit value on stock input account should be equal to the original PO price of the product.")
def test_valuation_from_increasing_tax(self):
""" Check that a tax without account will increment the stock value.
@@ -607,14 +607,14 @@ class TestStockValuationWithCOA(AccountTestInvoicingCommon):
diff_aml = invoice_amls - payable_aml
# check USD
self.assertAlmostEqual(payable_aml.debit, 50, "Total debit value should be equal to the original PO price of the product.")
self.assertAlmostEqual(picking_aml.credit, 10, "credit value for stock should be equal to the standard price of the product.")
self.assertAlmostEqual(diff_aml.credit, 40, "credit value for price difference")
self.assertAlmostEqual(payable_aml.debit, 50, msg="Total debit value should be equal to the original PO price of the product.")
self.assertAlmostEqual(picking_aml.credit, 10, msg="credit value for stock should be equal to the standard price of the product.")
self.assertAlmostEqual(diff_aml.credit, 40, msg="credit value for price difference")
# check EUR
self.assertAlmostEqual(payable_aml.amount_currency, 100, "Total debit value should be equal to the original PO price of the product.")
self.assertAlmostEqual(picking_aml.amount_currency, -20, "credit value for stock should be equal to the standard price of the product.")
self.assertAlmostEqual(diff_aml.amount_currency, -80, "credit value for price difference")
self.assertAlmostEqual(payable_aml.amount_currency, 100, msg="Total debit value should be equal to the original PO price of the product.")
self.assertAlmostEqual(picking_aml.amount_currency, -20, msg="credit value for stock should be equal to the standard price of the product.")
self.assertAlmostEqual(diff_aml.amount_currency, -80, msg="credit value for price difference")
def test_valuation_multicurecny_with_tax(self):
""" Check that a tax without account will increment the stock value.
@@ -705,8 +705,8 @@ class TestStockValuationWithCOA(AccountTestInvoicingCommon):
picking_aml = input_amls - invoice_aml
# check EUR
self.assertAlmostEqual(invoice_aml.amount_currency, 100, "Total debit value should be equal to the original PO price of the product.")
self.assertAlmostEqual(picking_aml.amount_currency, -95, "credit value for stock should be equal to the untaxed price of the product.")
self.assertAlmostEqual(invoice_aml.amount_currency, 100, msg="Total debit value should be equal to the original PO price of the product.")
self.assertAlmostEqual(picking_aml.amount_currency, -95, msg="credit value for stock should be equal to the untaxed price of the product.")
def test_average_realtime_anglo_saxon_valuation_multicurrency_same_date(self):
"""
@@ -1409,13 +1409,13 @@ class TestStockValuationWithCOA(AccountTestInvoicingCommon):
# Check what was posted in the price difference account
price_diff_aml = self.env['account.move.line'].search([('account_id','=', self.price_diff_account.id)])
self.assertEqual(len(price_diff_aml), 1, "Only one line should have been generated in the price difference account.")
self.assertAlmostEqual(price_diff_aml.credit, 20, "Price difference should be equal to 20 (110-90)")
self.assertAlmostEqual(price_diff_aml.credit, 20, msg="Price difference should be equal to 20 (110-90)")
# Check what was posted in stock input account
input_aml = self.env['account.move.line'].search([('account_id','=', self.stock_input_account.id)])
self.assertEqual(len(input_aml), 3, "Only two lines should have been generated in stock input account: one when receiving the product, two when making the invoice.")
self.assertAlmostEqual(sum(input_aml.mapped('debit')), 110, "Total debit value on stock input account should be equal to the original PO price of the product.")
self.assertAlmostEqual(sum(input_aml.mapped('credit')), 110, "Total credit value on stock input account should be equal to the original PO price of the product.")
self.assertAlmostEqual(sum(input_aml.mapped('debit')), 110, msg="Total debit value on stock input account should be equal to the original PO price of the product.")
self.assertAlmostEqual(sum(input_aml.mapped('credit')), 110, msg="Total credit value on stock input account should be equal to the original PO price of the product.")
def test_anglosaxon_valuation_discount(self):
"""
@@ -1456,13 +1456,13 @@ class TestStockValuationWithCOA(AccountTestInvoicingCommon):
# Check what was posted in the price difference account
price_diff_aml = self.env['account.move.line'].search([('account_id', '=', self.price_diff_account.id)])
self.assertEqual(len(price_diff_aml), 1, "Only one line should have been generated in the price difference account.")
self.assertAlmostEqual(price_diff_aml.credit, 10, "Price difference should be equal to 10 (100-90)")
self.assertAlmostEqual(price_diff_aml.credit, 10, msg="Price difference should be equal to 10 (100-90)")
# Check what was posted in stock input account
input_aml = self.env['account.move.line'].search([('account_id', '=', self.stock_input_account.id)])
self.assertEqual(len(input_aml), 3, "Three lines generated in stock input account: one when receiving the product, two when making the invoice.")
self.assertAlmostEqual(sum(input_aml.mapped('debit')), 100, "Total debit value on stock input account should be equal to the original PO price of the product.")
self.assertAlmostEqual(sum(input_aml.mapped('credit')), 100, "Total credit value on stock input account should be equal to the original PO price of the product.")
self.assertAlmostEqual(sum(input_aml.mapped('debit')), 100, msg="Total debit value on stock input account should be equal to the original PO price of the product.")
self.assertAlmostEqual(sum(input_aml.mapped('credit')), 100, msg="Total credit value on stock input account should be equal to the original PO price of the product.")
def test_anglosaxon_valuation_price_unit_diff_discount(self):
"""
@@ -1507,8 +1507,8 @@ class TestStockValuationWithCOA(AccountTestInvoicingCommon):
# Check what was posted in stock input account
input_aml = self.env['account.move.line'].search([('account_id','=', self.stock_input_account.id)])
self.assertEqual(len(input_aml), 2, "Only two lines should have been generated in stock input account: one when receiving the product, one when making the invoice.")
self.assertAlmostEqual(sum(input_aml.mapped('debit')), 90, "Total debit value on stock input account should be equal to the original PO price of the product.")
self.assertAlmostEqual(sum(input_aml.mapped('credit')), 90, "Total credit value on stock input account should be equal to the original PO price of the product.")
self.assertAlmostEqual(sum(input_aml.mapped('debit')), 90, msg="Total debit value on stock input account should be equal to the original PO price of the product.")
self.assertAlmostEqual(sum(input_aml.mapped('credit')), 90, msg="Total credit value on stock input account should be equal to the original PO price of the product.")
def test_anglosaxon_valuation_price_unit_diff_avco(self):
"""
@@ -160,9 +160,9 @@ class TestSaleMrpKitBom(TransactionCase):
self.assertEqual(len(amls), 4)
stock_out_aml = amls.filtered(lambda aml: aml.account_id == self.stock_output_account)
self.assertEqual(stock_out_aml.debit, 0)
self.assertAlmostEqual(stock_out_aml.credit, 1.53, "Should not include the value of consumable component")
self.assertAlmostEqual(stock_out_aml.credit, 1.53, msg="Should not include the value of consumable component")
cogs_aml = amls.filtered(lambda aml: aml.account_id == self.expense_account)
self.assertAlmostEqual(cogs_aml.debit, 1.53, "Should not include the value of consumable component")
self.assertAlmostEqual(cogs_aml.debit, 1.53, msg="Should not include the value of consumable component")
self.assertEqual(cogs_aml.credit, 0)
def test_reset_avco_kit(self):