Comments

blueminds’s picture

Status: Active » Needs review
StatusFileSize
new4.33 KB

Here is a first try. I am not sure about the 100 multiplier, maybe double field?

Status: Needs review » Needs work

The last submitted patch, tmgmt-remote_amount_currency-2112077-1.patch, failed testing.

blueminds’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, tmgmt-remote_amount_currency-2112077-1.patch, failed testing.

blueminds’s picture

Status: Needs work » Needs review
StatusFileSize
new4.45 KB
new1.02 KB
berdir’s picture

Status: Needs review » Needs work
  1. +++ b/controller/tmgmt.controller.remote.inc
    @@ -12,10 +12,26 @@
    +  public function save($entity, DatabaseTransaction $transaction = NULL) {
    +    if (strpos($entity->amount, '.') !== FALSE) {
    +      $entity->amount = $entity->amount * 100;
    +    }
    +    return parent::save($entity, $transaction);
    +  }
    ...
         foreach ($entities as &$entity) {
    +      if (strpos($entity->amount, '.') === FALSE) {
    +        $entity->amount = $entity->amount / 100;
    +      }
    

    Currency amounts should never be stored in floats. this could lead to rounding errors.

    Currency must always be stored in the smallest available unit for a given currency, see how commerce handles it.

    The translator is responsible for formatting the currency.

  2. +++ b/tmgmt.install
    @@ -151,6 +151,19 @@ function tmgmt_schema() {
    +      'amount' => array(
    +        'type' => 'int',
    +        'not null' => TRUE,
    +        'default' => 0,
    +        'description' => 'Amount charged for the remote translation job.',
    +      ),
    

    Just to be sure, maybe make set size to big or so? (not sure what the default is right now).

blueminds’s picture

Status: Needs work » Needs review
StatusFileSize
new1.32 KB
new1.32 KB

In commerce they do multiply the amount. But in there the multiplier is a setting and I do not think that making it a setting in our case is a way to go. So what i did now is checking the number of digits after the decimal point and cutting off all those that come after the second. Then multiplying it by 100 to make it a whole number.

Status: Needs review » Needs work

The last submitted patch, tmgmt-remote_amount_currency-2112077-3.patch, failed testing.

blueminds’s picture

Status: Needs work » Needs review
StatusFileSize
new8.98 KB
new5.22 KB

Moving the amount transition to translator

berdir’s picture

Status: Needs review » Needs work
  1. +++ b/README.txt
    @@ -118,8 +118,6 @@ The main features of the core system include:
     - A suggestions system that makes recommendations about related content that
       could be translated with the same job.
    -- Sources can declare which parts of a source text should not be translated,
    -  for example placeholders for user interface strings.
     
     The following sources are currently supported:
     
    @@ -135,10 +133,6 @@ The following sources are currently supported:
    
    @@ -135,10 +133,6 @@ The following sources are currently supported:
       to translate various configuration elements of a site: blocks, terms, fields,
       node types, contact categories and many more.
     
    -- Locale
    -  Allows to translate locale strings. Currently limited to the default
    -  textgroup (user interface strings passed through t()).
    -
     Two translators are included in the project:
    ...
     - File translator
    

    Uh, it shouldn't do this? :)

  2. +++ b/controller/tmgmt.controller.remote.inc
    @@ -12,12 +12,33 @@
    +  /**
    +   * {@inheritdoc}
    +   */
    +  public function save($entity, DatabaseTransaction $transaction = NULL) {
    +    /** @var TMGMTRemote $entity */
    +    $entity->amount = $entity->getJob()->getTranslatorController()->amountToInt($entity->amount, $entity->currency);
    +    return parent::save($entity, $transaction);
    +  }
    +
    ...
         $entities = parent::load($ids, $conditions);
    +    $translator_controller = NULL;
     
    +    /** @var TMGMTRemote $entity */
         foreach ($entities as &$entity) {
    -      if (is_string($entity->remote_data)) {
    -        $entity->remote_data = unserialize($entity->remote_data);
    +      // A possible approach is to load the translator controller for the first
    +      // job and reuse it in the following iterations. This can work in most of
    +      // the cases as remote mapping entities are usually loaded for a specific
    +      // translator. However if we have a case when remote mapping entities are
    +      // loaded across different translators, then we might get a wrong
    +      // conversion which would be difficult to track down. For that reason we
    +      // do load translator controller for each entity.
    +      if ($entity->getJob() != FALSE) {
    +        $entity->amount = $entity->getJob()->getTranslatorController()->amountToFloat($entity->amount, $entity->currency);
           }
    

    Still too much logic :)

    tmgmt_remote shouldn't care at all about it. It's an integer, any input must be an integer.

    If gengo returns us a float, then we need to convert it there. And then when we display it in the table. No need for new methods on the interface or so. Storage should always be in int.

blueminds’s picture

Issue summary: View changes
Status: Needs work » Needs review
StatusFileSize
new3.91 KB
new4.11 KB

Okay, so tmgmt core only provides the fields currency and amount. How they are handled it is upon translators.

The interdiff is not that correct, missing update of tmgmt_test and tmgmt.crud.test. However the patch itself is now so small it should not be an issue.

Status: Needs review » Needs work

The last submitted patch, 11: tmgmt-remote_amount_currency-2112077-5.patch, failed testing.

blueminds’s picture

The fail here is fixed by https://drupal.org/comment/8175519#comment-8175519

How do we proceed in such case?

berdir’s picture

The easiest thing would be to extract the fix in a separate issue, commit it and then move on.

blueminds’s picture

Here is the extracted patch: https://drupal.org/node/2136499

berdir’s picture

Status: Needs work » Needs review
berdir’s picture

Status: Needs review » Fixed

Thanks, finally committed and pushed!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.