Coder Social home page Coder Social logo

Comments (5)

shameemalim avatar shameemalim commented on July 17, 2024 1

any hope?

from odoo-rpc-dart.

lem8r avatar lem8r commented on July 17, 2024

Are you setting bin_size=True in the context? Which field of ir.attachment are you reading?

from odoo-rpc-dart.

shameemalim avatar shameemalim commented on July 17, 2024

i m reading 'datas' field.. i tried with bin_size=True and bin_size=False both

from odoo-rpc-dart.

BARSHA-ABHILASHA avatar BARSHA-ABHILASHA commented on July 17, 2024

List attachmentIds = [];
if (_attachmentResult != null && _attachmentResult!.files.isNotEmpty) {
final attachmentInfo = _attachmentResult!.files.first;
print('Selected attachmentInfo: $attachmentInfo');

   final attachmentData = attachmentInfo.bytes ??
        await File(attachmentInfo.path!).readAsBytes();
    print('Read attachmentData: $attachmentData');

    if (attachmentData != null) {
      final attachment = await orpc?.callKw({
        'model': 'ir.attachment',
        'method': 'create',
        'args': [
          {
            'name': attachmentInfo.name,
            'type': 'binary',
            'datas': base64Encode(attachmentData),
            'res_model': 'crm.lead',
            'res_id': widget.messageId,
            'mimetype': attachmentInfo.extension != null
                ? 'application/${attachmentInfo.extension}'
                : 'application/octet-stream',
          }
        ],
        'kwargs': {
          'context': {'bin_size': true}
        },
      });

      print('Created attachment with ID: $attachment');
      attachmentIds.add(attachment);
    } else {
      print('Failed to read attachment data.');
    }
  } else {
    print('No attachment selected.');
  }

  print('Creating message...');
  final message = await orpc?.callKw({
    'model': 'mail.message',
    'method': 'create',
    'args': [
      {
        'model': 'crm.lead',
        'body': _responseController.text,
        'res_id': widget.messageId,
        'message_type': 'comment',
        'subtype_id': 1,
        'attachment_ids': attachmentIds.isNotEmpty
            ? [
                [6, 0, attachmentIds]
              ]
            : [],
      }
    ],
    'kwargs': {
      'context': {'bin_size': true}
    },
  });

  if (message != null) {
    print('Created message with ID: $message');
    _responseController.clear();
    setState(() {
      _attachmentResult = null;
    });
    fetchResponse(); // Refresh the messages list
  }
  
  check this one  use filepicker for this 

from odoo-rpc-dart.

BARSHA-ABHILASHA avatar BARSHA-ABHILASHA commented on July 17, 2024

any hope?

once check the code i mentioned

from odoo-rpc-dart.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.