Skip to content

Commit

Permalink
[16.0][MIG] account_picking_anglo_saxon_sync
Browse files Browse the repository at this point in the history
  • Loading branch information
cormaza committed Apr 22, 2024
1 parent 402e83a commit 2903a28
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 24 deletions.
2 changes: 1 addition & 1 deletion account_picking_anglo_saxon_sync/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Invoice Picking Anglo Saxon Sync",
"version": "15.0.1.0.0",
"version": "16.0.1.0.0",
"summary": "Invoice Picking Anglo Saxon Sync",
"category": "Accounting",
"author": "Christopher Ormaza",
Expand Down
4 changes: 3 additions & 1 deletion account_picking_anglo_saxon_sync/models/account_move.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from odoo import api, fields, models

# flake8: noqa: B023


class AccountMove(models.Model):
_inherit = "account.move"
Expand Down Expand Up @@ -32,7 +34,7 @@ class AccountMoveLine(models.Model):
def _compute_anglo_saxon_line(self):
for rec in self:
anglo_saxon_line_ids = rec.move_id.line_ids.filtered(
lambda x: x.is_anglo_saxon_line
lambda x: x.display_type == "cogs"
and x.product_id == rec.product_id
and x.product_uom_id == rec.product_uom_id
and x.quantity == rec.quantity
Expand Down
8 changes: 8 additions & 0 deletions account_picking_anglo_saxon_sync/models/stock_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ def _sync_anglo_saxon_values(self):
"price_unit": prices_difference * -1,
}
)
credit_line.pop("balance")
credit_line.pop("amount_currency")
credit_line.pop("price_total")
credit_line.pop("price_subtotal")
debit_line.update(
{
"anglo_saxon_adjusted_line_id": credit_line.get(
Expand All @@ -73,6 +77,10 @@ def _sync_anglo_saxon_values(self):
"price_unit": prices_difference * -1,
}
)
debit_line.pop("balance")
debit_line.pop("amount_currency")
debit_line.pop("price_total")
debit_line.pop("price_subtotal")
for column in MAGIC_COLUMNS:
if column in credit_line:
credit_line.pop(column)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,67 @@
from odoo import fields
from odoo.tests import Form, TransactionCase


class TestAccountPickingAngloSaxonSync(TransactionCase):
def setUp(self):
super().setUp()
self.product_uom = self.env.ref("uom.product_uom_unit")
self.company = self.env.ref("base.main_company")
self.company.write({"anglo_saxon_accounting": True})
self.stock_picking_type_out = self.env.ref("stock.picking_type_out")
self.stock_picking_type_in = self.env.ref("stock.picking_type_in")
self.stock_location_id = self.env.ref("stock.stock_location_stock")
self.stock_location_customer_id = self.env.ref("stock.stock_location_customers")
self.stock_location_supplier_id = self.env.ref("stock.stock_location_suppliers")
self.supplier = self.env["res.partner"].create({"name": "Test supplier"})
self.customer = self.env["res.partner"].create({"name": "Test customer"})

self.fifo_product = self.env.ref(
from odoo.tests import Form, tagged

from odoo.addons.stock_account.tests.test_anglo_saxon_valuation_reconciliation_common import ( # noqa: E501
ValuationReconciliationTestCommon,
)


@tagged("post_install", "-at_install")
class TestAccountPickingAngloSaxonSync(ValuationReconciliationTestCommon):
@classmethod
def setUpClass(cls, chart_template_ref=None):
super().setUpClass(chart_template_ref=chart_template_ref)
cls.env = cls.env(
context=dict(
cls.env.context,
mail_create_nolog=True,
mail_create_nosubscribe=True,
mail_notrack=True,
no_reset_password=True,
tracking_disable=True,
)
)

cls.stock_account_product_categ_avg = cls.env["product.category"].create(
{
"name": "Test category",
"property_valuation": "real_time",
"property_cost_method": "average",
"property_stock_valuation_account_id": cls.company_data[
"default_account_stock_valuation"
].id,
"property_stock_account_input_categ_id": cls.company_data[
"default_account_stock_in"
].id,
"property_stock_account_output_categ_id": cls.company_data[
"default_account_stock_out"
].id,
}
)

cls.product_uom = cls.env.ref("uom.product_uom_unit")
cls.company = cls.env.ref("base.main_company")
cls.env.company.write({"anglo_saxon_accounting": True})
cls.stock_picking_type_out = cls.env.ref("stock.picking_type_out")
cls.stock_picking_type_in = cls.env.ref("stock.picking_type_in")
cls.stock_location_id = cls.env.ref("stock.stock_location_stock")
cls.stock_location_customer_id = cls.env.ref("stock.stock_location_customers")
cls.stock_location_supplier_id = cls.env.ref("stock.stock_location_suppliers")
cls.supplier = cls.env["res.partner"].create({"name": "Test supplier"})
cls.customer = cls.env["res.partner"].create({"name": "Test customer"})

cls.fifo_product = cls.env.ref(
"account_picking_anglo_saxon_sync.fifo_product_demo"
)
self.avg_product = self.env.ref(
cls.avg_product = cls.env.ref(
"account_picking_anglo_saxon_sync.avg_product_demo"
)

def _do_picking(self, picking, date, qty):
"""Do picking with only one move on the given date."""
picking.action_confirm()
picking.action_assign()
picking.move_lines.quantity_done = qty
picking.move_ids.quantity_done = qty
res = picking.button_validate()
if isinstance(res, dict) and res:
backorder_wiz_id = res["res_id"]
Expand Down Expand Up @@ -61,6 +95,15 @@ def _make_purchase_order(self, product, quantity, price_unit, supplier=False):
return purchase

def test_01_invoice_before_picking(self):
self.fifo_product.write(
{"standard_price": 10.0, "categ_id": self.stock_account_product_categ.id}
)
self.avg_product.write(
{
"standard_price": 10.0,
"categ_id": self.stock_account_product_categ_avg.id,
}
)
self.assertEqual(self.fifo_product.standard_price, 10.0)
po1 = self._make_purchase_order(self.fifo_product, 10.0, 15.0)
self._do_picking(po1.picking_ids, fields.Datetime.now(), 10.0)
Expand All @@ -74,11 +117,11 @@ def test_01_invoice_before_picking(self):
so1 = self._make_sale_order(self.fifo_product + self.avg_product, 1.0)
self._do_picking(so1.picking_ids, fields.Datetime.now(), 1.0)

fifo_layers = so1.picking_ids.move_lines.filtered(
fifo_layers = so1.picking_ids.move_ids.filtered(
lambda x: x.product_id == self.fifo_product
).stock_valuation_layer_ids
self.assertEqual(sum(fifo_layers.mapped("value")), -15.0)
avg_layers = so1.picking_ids.move_lines.filtered(
avg_layers = so1.picking_ids.move_ids.filtered(
lambda x: x.product_id == self.avg_product
).stock_valuation_layer_ids
self.assertEqual(sum(avg_layers.mapped("value")), -15.0)
Expand Down

0 comments on commit 2903a28

Please sign in to comment.