Skip to content
Merged
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: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Unreleased

- A credit note has a language (`lang_id`), chosen in the back-office modal: the language of its order by default, of its customer without an order, the default language of the shop otherwise. It stays editable once the credit note is numbered, since it only changes the printed document. The document is printed in it (still within `document_locales`). The update fills the existing credit notes with the language they were printed in: the one of their customer, of their order when the customer has none.
- The colors of the status and type badges are written into `style` attributes only when they are hexadecimal colors, grey otherwise.
- A credit note created or saved without an invoice address (no customer picked, or "Other" with the name left empty) is refused with a message, and nothing is written. The controller used to save the empty address, which a database in strict mode refuses with an error 500 (`Field 'firstname' doesn't have a default value`). The module's back-office messages use the `danger` type, the one the Twig back office styles.
- `update()` runs the scripts of `Config/Update/sql/` from the version installed up to the target version only, compared by version (the file name without `.sql`). It used to run every script above the installed version, which replayed `4.3.0.sql` on a shop already at 4.3.0.
- After creating, updating or deleting a credit note, the administrator is back on the page the modal was opened from, on the tab that held it ("Credit note" of an order): the modal script sends that page as `success-url`, which the modal kept only from the query string. Only a path of the shop in printable ASCII is followed: an absolute or protocol-relative `success-url`, or one carrying a tab or a line break that the browser would drop, sends back to the order.
- The "Credit Notes" section of the admin side menu is back, right below "Orders": its script looked for the `#orders_menu` entry of the Smarty back-office, absent from default-twig. It now follows the entry `[data-testid="bo-nav-order"]` of the default-twig side menu, which has no hook between sections.
- Smarty is gone, as in Thelia 3: the Smarty plugin `credit_note_format_address`, the Smarty back-office and PDF templates, the Smarty fallback of the back-office hooks. The loops no Twig template calls are removed too: `credit-note-comment`, `credit-note-status`, `credit-note-type`, `order-credit-note` and `credit-note-version` (its table has not existed since 2.3.4). The loops `credit-note`, `credit-note-address` and `credit-note-detail` stay: the credit note document of the PDF template reads them.
- The languages a credit note is printed in are a setting of the module (`document_locales`, locales separated by commas): a customer whose language is in the list gets the document in that language, the others the default language of the shop. Empty, as before: English and French. A shop whose PDF template is translated in German adds `de_DE`. The field refuses anything that is not a list of locales such as `fr_FR`.
- Credit notes numbered like the invoices (`invoice_ref_with_thelia_order`) draw their number from `InvoiceRefSequence::next()` (InvoiceRef 3.1 or later): the counter is read under a lock shared with the orders, and a number an order already carries is skipped. The previous read and increment, without a lock, could hand the same number to an invoice and a credit note.
Expand Down
25 changes: 25 additions & 0 deletions Config/Update/sql/4.3.0.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# This is a fix for InnoDB in MySQL >= 4.1.x
# It "suspends judgement" for fkey relationships until are tables are set.
SET FOREIGN_KEY_CHECKS = 0;

ALTER TABLE `credit_note` ADD `lang_id` INTEGER AFTER `allow_partial_use`;
ALTER TABLE `credit_note` ADD INDEX `idx_lang_id_fk` (`lang_id`);
ALTER TABLE `credit_note` ADD CONSTRAINT `credit_note_FK_8`
FOREIGN KEY (`lang_id`)
REFERENCES `lang` (`id`)
ON UPDATE RESTRICT
ON DELETE SET NULL;

# The existing credit notes keep the language they were printed in until now: the one of their
# customer, or of their order when the customer has none. Only a language that exists: the foreign
# key checks are off in this script.
UPDATE `credit_note`
LEFT JOIN `customer` ON `customer`.`id` = `credit_note`.`customer_id`
LEFT JOIN `lang` `customer_lang` ON `customer_lang`.`id` = `customer`.`lang_id`
LEFT JOIN `order` ON `order`.`id` = `credit_note`.`order_id`
LEFT JOIN `lang` `order_lang` ON `order_lang`.`id` = `order`.`lang_id`
SET `credit_note`.`lang_id` = COALESCE(`customer_lang`.`id`, `order_lang`.`id`)
WHERE `credit_note`.`lang_id` IS NULL;

# This restores the fkey checks, after having unset them earlier
SET FOREIGN_KEY_CHECKS = 1;
2 changes: 1 addition & 1 deletion Config/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<language>en_US</language>
<language>fr_FR</language>
</languages>
<version>4.2.0</version>
<version>4.3.0</version>
<author>
<name>Gilles Bourgeat</name>
<email>gbourgeat@openstudio.fr</email>
Expand Down
10 changes: 10 additions & 0 deletions Config/schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

<column name="allow_partial_use" type="BOOLEAN" defaultValue="1" />

<column name="lang_id" type="INTEGER" required="false" />

<foreign-key foreignTable="order" onDelete="RESTRICT" onUpdate="RESTRICT">
<reference local="order_id" foreign="id" />
</foreign-key>
Expand Down Expand Up @@ -56,6 +58,10 @@
<reference local="invoice_address_id" foreign="id" />
</foreign-key>

<foreign-key foreignTable="lang" onDelete="SET NULL" onUpdate="RESTRICT">
<reference local="lang_id" foreign="id" />
</foreign-key>

<unique name="ref_UNIQUE">
<unique-column name="ref" />
</unique>
Expand Down Expand Up @@ -84,6 +90,10 @@
<index-column name="status_id" />
</index>

<index name="idx_lang_id_fk">
<index-column name="lang_id" />
</index>

<behavior name="timestampable" />
</table>

Expand Down
9 changes: 8 additions & 1 deletion Config/thelia.sql
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ CREATE TABLE `credit_note`
`discount_without_tax` DECIMAL(16,6) DEFAULT 0.000000,
`discount_with_tax` DECIMAL(16,6) DEFAULT 0.000000,
`allow_partial_use` TINYINT(1) DEFAULT 1,
`lang_id` INTEGER,
`created_at` DATETIME,
`updated_at` DATETIME,
PRIMARY KEY (`id`),
Expand All @@ -38,6 +39,7 @@ CREATE TABLE `credit_note`
INDEX `idx_parent_id_fk` (`parent_id`),
INDEX `idx_type_id_fk` (`type_id`),
INDEX `idx_status_id_fk` (`status_id`),
INDEX `idx_lang_id_fk` (`lang_id`),
INDEX `credit_note_FI_6` (`currency_id`),
INDEX `credit_note_FI_7` (`invoice_address_id`),
CONSTRAINT `credit_note_FK_1`
Expand Down Expand Up @@ -74,7 +76,12 @@ CREATE TABLE `credit_note`
FOREIGN KEY (`invoice_address_id`)
REFERENCES `credit_note_address` (`id`)
ON UPDATE RESTRICT
ON DELETE RESTRICT
ON DELETE RESTRICT,
CONSTRAINT `credit_note_FK_8`
FOREIGN KEY (`lang_id`)
REFERENCES `lang` (`id`)
ON UPDATE RESTRICT
ON DELETE SET NULL
) ENGINE=InnoDB;

-- ---------------------------------------------------------------------
Expand Down
Loading
Loading