Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] order line qty set to 0 on confirmed SO #12

Open
wants to merge 3 commits into
base: 14.0-ADD-account_global_discount_amount
Choose a base branch
from
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
38 changes: 29 additions & 9 deletions account_global_discount_amount/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,17 @@ class AccountMoveLine(models.Model):
_name = "account.move.line"

def _create_discount_lines(self, move):
if (
move.invoice_origin
and len(
self.env["account.move"].search(
[("invoice_origin", "=", move.invoice_origin)]
)
)
> 1
):
# we assume this is a credit note no discount creation needed
return
amount_untaxed = move.amount_untaxed
# create discount lines by tax line
with_tax_lines = move.line_ids.filtered(lambda x: x.tax_line_id)
Expand All @@ -89,7 +100,7 @@ def _create_discount_lines(self, move):
amount_untaxed=amount_untaxed,
)
# create one discount line for the all invoice lines without tax lines
lines_with_tax = move.line_ids.filtered(lambda x: x.tax_ids)
lines_with_tax = move.line_ids.filtered(lambda x: x.tax_ids and x.quantity)
line_tax_ids = lines_with_tax.tax_ids - with_tax_lines.tax_line_id
without_tax_lines = move.invoice_line_ids.filtered(
lambda x: x.tax_ids == line_tax_ids
Expand All @@ -111,15 +122,24 @@ def _create_one_discount_line(self, move, tax_ids, tax_base_amount, amount_untax
discount_product = self.env.ref(
"account_global_discount_amount.discount_product"
)
discount_line = self.with_context(check_move_validity=False).create(
{
"product_id": discount_product.id,
"move_id": move.id,
"partner_id": move.partner_id.id,
"quantity": 1,
"account_id": move.line_ids[0]._get_computed_account().id,
}
discount_line = self.search(
[
("product_id", "=", discount_product.id),
("move_id", "=", move.id),
("tax_ids", "=", tax_ids[0][2][0]),
],
limit=1,
)
if not len(discount_line):
discount_line = self.with_context(check_move_validity=False).create(
{
"product_id": discount_product.id,
"move_id": move.id,
"partner_id": move.partner_id.id,
"quantity": 1,
"account_id": move.line_ids[0]._get_computed_account().id,
}
)
discount_line._onchange_product_id()
price_unit = discount_line._prepare_discount_line_vals(
amount_untaxed=amount_untaxed,
Expand Down
5 changes: 4 additions & 1 deletion account_global_discount_amount/models/discount_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,7 @@ class DiscountLineMixin(models.AbstractModel):
def _prepare_discount_line_vals(
self, amount_untaxed, tax_base_amount, global_discount_amount
):
return (tax_base_amount / amount_untaxed) * global_discount_amount
if amount_untaxed:
return (tax_base_amount / amount_untaxed) * global_discount_amount
else:
return 0