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

[16.0][FW] [15.0][IMP] product_pricelist_direct_print: Allow printing the products sold to a client from x date #1866

Open
wants to merge 1 commit into
base: 16.0
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
18 changes: 15 additions & 3 deletions product_pricelist_direct_print/wizards/product_pricelist_print.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@
lang = fields.Selection(
_lang_get, string="Language", default=lambda self: self.env.user.lang
)
product_selling_date_threshold = fields.Datetime(
string="Selling date threshold",
help="Filter only the products ordered since this date",
)

product_price = fields.Float(compute="_compute_product_price")

Expand Down Expand Up @@ -268,10 +272,15 @@

@api.model
def _get_sale_order_domain(self, partner):
return [
domain = [
("state", "not in", ["draft", "sent", "cancel"]),
("partner_id", "child_of", partner.id),
]
if self.product_selling_date_threshold:
domain = expression.AND(

Check warning on line 280 in product_pricelist_direct_print/wizards/product_pricelist_print.py

View check run for this annotation

Codecov / codecov/patch

product_pricelist_direct_print/wizards/product_pricelist_print.py#L280

Added line #L280 was not covered by tests
[domain, [("date_order", ">=", self.product_selling_date_threshold)]]
)
Comment on lines +280 to +282
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
domain = expression.AND(
[domain, [("date_order", ">=", self.product_selling_date_threshold)]]
)
domain.append(("date_order", ">=", self.product_selling_date_threshold))

I know I review the PR in the previous version and I didn't put this suggestion, but seeing that it's a very simple domain we can save ourselves the use of expression.AND.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expression.AND is more explicit. And that is exactly the objective of this function.

return domain

def get_last_ordered_products_to_print(self):
self.ensure_one()
Expand All @@ -283,7 +292,10 @@
)
orders = orders.sorted(key=lambda r: r.date_order, reverse=True)
products = orders.mapped("order_line").mapped("product_id")
return products[: self.last_ordered_products]
if self.last_ordered_products:
return products[: self.last_ordered_products]
else:
return products

Check warning on line 298 in product_pricelist_direct_print/wizards/product_pricelist_print.py

View check run for this annotation

Codecov / codecov/patch

product_pricelist_direct_print/wizards/product_pricelist_print.py#L298

Added line #L298 was not covered by tests

def get_pricelist_to_print(self):
self.ensure_one()
Expand Down Expand Up @@ -346,7 +358,7 @@

def get_products_to_print(self):
self.ensure_one()
if self.last_ordered_products:
if self.last_ordered_products or self.product_selling_date_threshold:
products = self.get_last_ordered_products_to_print()
else:
if self.show_variants:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@
name="last_ordered_products"
attrs="{'invisible':[('partner_count','=',0)]}"
/>
<field
name="product_selling_date_threshold"
attrs="{'invisible':[('partner_count','=',0)]}"
/>
</group>
</group>
<notebook>
Expand Down
Loading