Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions account_cutoff_accrual_order_base/models/order_line_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,10 @@ def _get_cutoff_accrual_taxes(self, cutoff, quantity):

@api.model
def _get_cutoff_accrual_lines_domain(self, cutoff):
domain = []
domain.append(("is_cutoff_accrual_excluded", "!=", True))
domain = [
("is_cutoff_accrual_excluded", "!=", True),
("company_id", "=", cutoff.company_id.id),
]
return domain

@api.model
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def _get_cutoff_accrual_lines_invoiced_after(self, cutoff):
# Take all invoices impacting the cutoff
# FIXME: what about ("move_id.payment_state", "=", "invoicing_legacy")
domain = [
("company_id", "=", cutoff.company_id.id),
("purchase_line_id.is_cutoff_accrual_excluded", "!=", True),
("move_id.move_type", "in", ("in_invoice", "in_refund")),
("purchase_line_id", "!=", False),
Expand All @@ -82,8 +83,9 @@ def _get_cutoff_accrual_lines_invoiced_after(self, cutoff):
FROM account_move_line
WHERE id in %s
)
AND company_id = %s
""",
(tuple(invoice_line_after.ids),),
(tuple(invoice_line_after.ids), cutoff.company_id.id),
)
purchase_ids = [x[0] for x in self.env.cr.fetchall()]
lines = self.env["purchase.order.line"].search(
Expand Down
86 changes: 86 additions & 0 deletions account_cutoff_accrual_purchase/tests/common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Copyright 2018 Jacques-Etienne Baudoux (BCIM) <je@bcim.be>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from datetime import datetime

from dateutil.relativedelta import relativedelta

from odoo import Command, fields
from odoo.tests.common import Form

from odoo.addons.account_cutoff_accrual_order_base.tests.common import (
TestAccountCutoffAccrualOrderCommon,
)


class TestAccountCutoffAccrualPurchaseCommon(TestAccountCutoffAccrualOrderCommon):
@classmethod
def setUpClass(cls):
super().setUpClass()
# Removing all existing PO
cls.env.cr.execute("DELETE FROM purchase_order;")
# Create PO
cls.tax_purchase = cls.env.company.account_purchase_tax_id
cls.cutoff_account = cls.env["account.account"].create(
{
"name": "account accrued expense",
"code": "accountAccruedExpense",
"account_type": "asset_current",
"company_id": cls.env.company.id,
}
)
cls.tax_purchase.account_accrued_expense_id = cls.cutoff_account
cls.po = cls.env["purchase.order"].create(
{
"partner_id": cls.partner.id,
"order_line": [
Command.create(
{
"name": p.name,
"product_id": p.id,
"product_qty": 5,
"product_uom": p.uom_po_id.id,
"price_unit": 100,
"date_planned": fields.Date.to_string(
datetime.today() + relativedelta(days=-15)
),
"analytic_distribution": {
str(cls.analytic_account.id): 100.0
},
"taxes_id": [Command.set(cls.tax_purchase.ids)],
},
)
for p in cls.products
],
}
)
type_cutoff = "accrued_expense"
cls.expense_cutoff = (
cls.env["account.cutoff"]
.with_context(default_cutoff_type=type_cutoff)
.create(
{
"cutoff_type": type_cutoff,
"order_line_model": "purchase.order.line",
"company_id": 1,
"cutoff_date": fields.Date.today(),
}
)
)

@classmethod
def _confirm_po(cls):
cls.po.button_confirm()
cls.po.button_approve(force=True)

@classmethod
def _create_po_invoice(cls, date):
invoice_form = Form(
cls.env["account.move"].with_context(
default_move_type="in_invoice", default_purchase_id=cls.po.id
)
)
invoice_form.invoice_date = date
invoice = invoice_form.save()
invoice.date = date
return invoice
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ def _get_cutoff_accrual_lines_delivered_after(self, cutoff):
AND date >= %s
AND purchase_line_id IS NOT NULL
)
AND company_id = %s
""",
(cutoff_nextday,),
(cutoff_nextday, cutoff.company_id.id),
)
purchase_ids = [x[0] for x in self.env.cr.fetchall()]
lines = self.env["purchase.order.line"].search(
Expand Down
6 changes: 4 additions & 2 deletions account_cutoff_accrual_sale/models/sale_order_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ def _get_cutoff_accrual_lines_invoiced_after(self, cutoff):
# Take all invoices impacting the cutoff
# FIXME: what about ("move_id.payment_state", "=", "invoicing_legacy")
domain = [
("company_id", "=", cutoff.company_id.id),
("sale_line_ids.is_cutoff_accrual_excluded", "!=", True),
("move_id.move_type", "in", ("out_invoice", "out_refund")),
("sale_line_ids", "!=", False),
Expand All @@ -130,8 +131,9 @@ def _get_cutoff_accrual_lines_invoiced_after(self, cutoff):
FROM sale_order_line_invoice_rel
WHERE invoice_line_id in %s
)
AND company_id = %s
""",
(tuple(invoice_line_after.ids),),
(tuple(invoice_line_after.ids), cutoff.company_id.id),
)
sale_ids = [x[0] for x in self.env.cr.fetchall()]
lines = self.env["sale.order.line"].search(
Expand Down Expand Up @@ -166,7 +168,7 @@ def _get_cutoff_accrual_delivered_min_date(self):
self.ensure_one()
if self.product_id.invoice_policy == "order":
date_local = self.order_id.date_order
company_tz = self.env.company.partner_id.tz or "UTC"
company_tz = self.company_id.partner_id.tz or "UTC"
date_utc = fields.Datetime.context_timestamp(
self.with_context(tz=company_tz),
date_local,
Expand Down
3 changes: 2 additions & 1 deletion account_cutoff_accrual_sale_stock/models/sale_order_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ def _get_cutoff_accrual_lines_delivered_after(self, cutoff):
AND date >= %s
AND sale_line_id IS NOT NULL
)
AND company_id = %s
""",
(cutoff_nextday,),
(cutoff_nextday, cutoff.company_id.id),
)
sale_ids = [x[0] for x in self.env.cr.fetchall()]
lines = self.env["sale.order.line"].search(
Expand Down
Loading