Commit Graph

130 Commits

Author SHA1 Message Date
Luis Ramos
c9a7a6e897 Merge branch 'master' into 3-0-stable-jun-2 2020-06-02 16:00:45 +01:00
Luis Ramos
758d7c82f7 Rename order_cycle.accessible_by to remove name clash with active record 2020-05-19 12:21:13 +01:00
Luis Ramos
19da0ba969 Merge branch 'master' into 3-0-stable-may13 2020-05-13 19:50:32 +01:00
Pau Pérez Fabregat
60470aaf9f Merge pull request #5332 from coopdevs/add-timestamps-to-oc-schedule
Add timestamps to OC schedule join table
2020-05-08 10:51:43 +02:00
Luis Ramos
be4104d6f3 Merge branch 'master' into 3-0-stable-may-5 2020-05-05 19:11:20 +01:00
Pau Perez
1903134e13 Add timestamps to OC schedule join table
This is critical to debug bugs related to subscriptions.

Essentially, `has_and_belongs_to_many` doesn't give us the option for
any other column that the foreign keys themselves:

> A has_and_belongs_to_many association creates a direct many-to-many
> connection with another model, with no intervening model.

Source: https://guides.rubyonrails.org/v3.2/association_basics.html#the-has_and_belongs_to_many-association

Note however, that there's no way to update an order_cycle_schedule,
that I can think of but `updated_at` doesn't do any harm.
2020-04-30 15:00:13 +02:00
Matt-Yorkley
92a881c584 Simplify relation used in #exchanges_supplying 2020-04-29 17:19:16 +02:00
Luis Ramos
839b373b5c Merge branch 'master' into 3-0-stable-Apr28 2020-04-28 13:40:19 +01:00
Matt-Yorkley
3fa2b3161f Avoid N+1s when using OrderCycle#exchanges_supplying 2020-04-28 01:10:07 +02:00
Luis Ramos
e5e9325499 Fix paper_trail custom_data for order_cycle, custom data must be a string, cant be an array 2020-03-25 15:35:51 +00:00
Luis Ramos
0815068050 Merge branch 'master' into 3-0-stable-mar6 2020-03-06 09:20:03 +00:00
Matt-Yorkley
cc1ab1bdb9 Fix issue with broken SQL fragments in scopes and nested subqueries
It looks like there are some issues with prepared statements here, where the resulting SQL contains something like: `WHERE "enterprise_roles"."user_id" = $1` in a subquery. The "$1" part is being lost somehow and isn't present if it's used in nested subqueries.

Example fixed spec (there are lots like this one):

  59) Spree::Admin::ReportsController Supplier Bulk Coop where I have granted P-OC to the distributor only shows product line items that I am supplying
      Failure/Error: produced_line_items.select("spree_line_items.id"))

      ActiveRecord::StatementInvalid:
        PG::ProtocolViolation: ERROR:  bind message supplies 0 parameters, but prepared statement "" requires 1
        : SELECT id FROM "spree_line_items"  WHERE "spree_line_items"."order_id" IN (SELECT id FROM "spree_orders"  WHERE (("spree_orders"."distributor_id" IN (SELECT enterprises.id FROM "enterprises" INNER JOIN "enterprise_roles" ON "enterprise_roles"."enterprise_id" = "enterprises"."id" WHERE (enterprise_roles.user_id = 947)) OR "spree_orders"."order_cycle_id" IN (SELECT id FROM "order_cycles"  WHERE "order_cycles"."coordinator_id" IN (SELECT "enterprises"."id" FROM "enterprises" INNER JOIN "enterprise_roles" ON "enterprises"."id" = "enterprise_roles"."enterprise_id" WHERE "enterprise_roles"."user_id" = $1)))))
      # ./app/services/permissions/order.rb:28:in `visible_line_items'
      # ./lib/open_food_network/reports/line_items.rb:16:in `list'
      # ./lib/open_food_network/bulk_coop_report.rb:54:in `table_items'
      # ./app/controllers/spree/admin/reports_controller.rb:264:in `order_grouper_table'
      # ./app/controllers/spree/admin/reports_controller.rb:101:in `bulk_coop'
      # ./spec/controllers/spree/admin/reports_controller_spec.rb:168:in `block (5 levels) in <top (required)>'
      # ------------------
      # --- Caused by: ---
      # PG::ProtocolViolation:
      #   ERROR:  bind message supplies 0 parameters, but prepared statement "" requires 1
      #   ./app/services/permissions/order.rb:28:in `visible_line_items'
2020-02-28 12:16:55 +01:00
Matt-Yorkley
98fdbb8621 Update deprecated #scoped calls
Model#scoped is now deprecated. Model#where(nil) in Rails 4 returns the same result as Model#scoped in Rails 3
2020-02-22 11:06:51 +00:00
Matt-Yorkley
6541b55872 Fix default_association deprecated syntax in OrderCycle and Schedule 2020-02-22 11:06:51 +00:00
luisramos0
abd4f0b923 Add custom_data column to paper_trail versions table so we can track a specific list of ids in a model
Activate paper_trail in order_cycles and schedules and track each others ids

An alternative way of doing this would be to use a gem for paper_trail associations but this way we avoid adding a new dependency to the app
2020-02-07 10:06:58 +00:00
Matt-Yorkley
59ebfb9bd4 Fix subquery errors triggered by #warn_invalid_order_cycles 2020-01-22 12:17:23 +01:00
Maikel Linke
abcfb5ce8d Update Rubocop config for new version
- A couple of cops moved into a different namespace.
- The target ruby version doesn't have to be specified, it's read from
  .ruby-version which has been updated to Ruby 2.3.
- Some files were missing in the todo lists.
2020-01-10 08:59:44 +11:00
luisramos0
9404aacfb2 run rubocop --auto-correct 2019-11-10 18:42:43 +00:00
Matt-Yorkley
ab330e882e Remove product cache 2019-10-18 21:15:11 +01:00
luisramos0
178924af5d Fix long lines in order_cycle model 2019-06-18 10:52:45 +01:00
luisramos0
9548f5c5f7 Adapt order_cycle scopes to rail 4 2019-06-18 10:40:49 +01:00
luisramos0
ba91abd20e Adapt exchanges.with_any_variant scope to rails 4 2019-06-18 10:40:49 +01:00
luisramos0
ffbd79d3dd Change all model scopes without a callable object to use a proc 2019-05-28 15:55:13 +01:00
luisramos0
86b0d71c7e Result of rubocop auto-correct and rebuilding rubocop_manual_todo 2019-05-28 12:57:29 +01:00
Kristina Lim
c0a5bcce92 Update some comments in Enterprise and OrderCycle models 2019-05-06 18:35:01 +08:00
Kristina Lim
781afc1015 Change OC :suppliers and :distributors to associations 2019-05-06 13:43:44 +10:00
luisramos0
60ee17204b Merge branch 'master' into 2-0-stable-Mar16 2019-03-16 16:17:38 +00:00
Pau Pérez Fabregat
13b2115a29 Merge pull request #3581 from coopdevs/cache-stylistic-improvements
Cache stylistic improvements
2019-03-13 19:05:38 +01:00
Pau Perez
347aa3c4ae Replace #valid_products_distributed_by by class 2019-03-06 15:06:00 +01:00
Pau Perez
7c533c6347 Extract DistributedValidProducts from OrderCycle 2019-03-06 13:35:43 +01:00
luisramos0
351555d4e2 Remove unused methods from add_to_cart helper and distribution change validator 2019-03-02 12:55:08 +00:00
Maikel Linke
99f0be2f1c Remove unnecessary scope Variant.not_deleted
Spree made that scope default so that we don't need to define or call
it. There might be cases in which we were showing deleted variants and
now we are not, but I have not idea how to find them.

Related Spree commit:
- cd3add960e
2019-02-19 14:25:18 +11:00
Pau Pérez Fabregat
0f627cdf39 Merge pull request #2661 from kristinalim/translations-copy_of_order_cycle
Translate "COPY OF" when cloning an OC
2018-09-17 12:38:29 +02:00
Maikel Linke
a447fe4f40 Require lib file where needed
We can't always rely on other parts of the code been loaded first. We
need to declare dependencies so that they are always present.

I just ran into this problem in my dev environment.
2018-09-13 12:01:16 +10:00
Kristina Lim
2c2dd62f6a Translate "COPY OF" when cloning an OC 2018-09-08 02:06:52 +08:00
Rob Harrington
b17d8c2fe3 Add validation of open and close dates for order cycles 2018-04-04 17:18:32 +10:00
Pau Perez
c79641c77c Fix typos in documentation 2018-02-09 09:53:40 +01:00
Rob Harrington
981b874263 Remove unused method active? for order cycles 2018-02-09 14:44:09 +11:00
Rob Harrington
2aad722b4b WIP, SO placement job: preventing payments on standing orders from being processed when OC opens 2018-02-09 14:43:40 +11:00
Rob Harrington
a25f2141a5 Adding Order Cycle Schedules join table 2018-02-09 14:43:27 +11:00
Pau Perez
6cb038c362 Autocorrect rubocop Layout/BlockEndNewline cop 2018-02-01 09:52:53 +01:00
Pau Perez
cee24dcca7 Use indented style for multiline method calls
This enables the Rubocop's Style/MultilineMethodCallIndentation cop with
indentend enforced style. Which makes you split multiline method calls like:

  orders = Spree::Order
    .an_scope
    .another_scope
    .where(id: list_of_ids)

It also autofixes the current violations and updates the
rubocop_todo.yml
2017-07-12 10:40:53 +02:00
Rob Harrington
7bb58342fc Rubocop: Auto-correct Style/EmptyLineBetweenDefs offences 2017-06-23 16:49:08 +10:00
Rob Harrington
e47e10d267 Removing n+1 query from #items_bought_by_user 2017-05-12 16:11:16 +10:00
Rob Harrington
314ccc2f27 Ensuring that #items_bought_by_user doesn't return items from cancelled orders 2017-05-05 14:20:57 +10:00
Rob Harrington
47011e11ff order_cycle.items_bought_by_user actually scopes to the current distributor 2017-05-05 14:20:57 +10:00
Maikel Linke
219ad4a3a7 Reload bought products after choosing order cycle 2017-05-05 14:19:32 +10:00
Rohan Mitchell
422061f137 Merge branch 'master' into products-caching
Conflicts:
	app/controllers/shop_controller.rb
	app/models/enterprise_fee.rb
	app/models/order_cycle.rb
	app/models/variant_override.rb
	db/schema.rb
	lib/open_food_network/products_renderer.rb
	spec/lib/open_food_network/products_renderer_spec.rb
2016-03-03 09:42:52 +11:00
Rob Harrington
f280b96215 Hiding a variant from inventory prevents it being available on the shopfront
User preferences around inventory-only product selection immediately affect the shopfront
2016-03-02 12:10:22 +11:00
Rob Harrington
77e74c5642 OC Coordinators can opt to restrict products in an order cycle to those in their inventory only 2016-03-02 12:10:22 +11:00