def _prepare_create(self, params):
        """Prepare a writable dictionary of values"""
        journal = self.env["account.journal"].search([("_api_external_id", "=",
                                                       params["journal"])])
        if not journal:
            raise wrapJsonException(
                NotFound(_("No journal %s on platform") % params["journal"]))

        invoice = self.env["account.invoice"].search([("_api_external_id", "=",
                                                       params["invoice"])])
        if not invoice:
            raise wrapJsonException(
                NotFound(_("No invoice %s on platform") % params["invoice"]))

        payment_method_id = self.env["account.payment.method"].search([
            ("code", "=", params["payment_method"]),
            ("payment_type", "=", params["payment_type"]),
        ])
        if not payment_method_id:
            codes = self.env["account.payment.method"].search(
                []).mapped("code")
            raise wrapJsonException(
                NotFound(_("Payment method must be one of %s") % codes))

        return {
            "payment_date": params["payment_date"],
            "amount": params["amount"],
            "payment_type": params["payment_type"],
            "communication": params["communication"],
            "invoice_ids": [(4, invoice.id, False)],
            "payment_method_id": payment_method_id.id,
            "journal_id": journal.id,
            "partner_type": "customer",
        }
Exemplo n.º 2
0
 def validate(self, _id, **params):
     sr = self.env["subscription.request"].search([("_api_external_id", "=",
                                                    _id)])
     if not sr:
         raise wrapJsonException(
             NotFound(_("No subscription request for id %s") % _id))
     if sr.state != "draft":
         raise wrapJsonException(
             BadRequest(
                 _("Subscription request %s is not in draft state") % _id))
     sr.validate_subscription_request()
     return self._to_dict(sr)
Exemplo n.º 3
0
 def _get_country(self, code):
     country = self.env["res.country"].search([("code", "=", code)])
     if country:
         return country
     else:
         raise wrapJsonException(
             BadRequest(_("No country for isocode %s") % code))
Exemplo n.º 4
0
 def get(self, _id):
     sr = self.env["subscription.request"].search([("_api_external_id", "=",
                                                    _id)])
     if sr:
         return self._to_dict(sr)
     else:
         raise wrapJsonException(
             NotFound(_("No subscription request for id %s") % _id))
Exemplo n.º 5
0
 def _get_share_product(self, template_id):
     product = self.env["product.product"].search([("product_tmpl_id", "=",
                                                    template_id)])
     if product:
         return product
     else:
         raise wrapJsonException(
             BadRequest(_("No share for id %s") % template_id))
 def get(self, _id):
     sr = self.env["account.invoice"].search([("_api_external_id", "=", _id)
                                              ])
     if sr:
         return self._to_dict(sr)
     else:
         raise wrapJsonException(
             NotFound(_("No invoice found for id %s") % _id))
Exemplo n.º 7
0
 def update(self, _id, **params):
     params = self._prepare_update(params)
     sr = self.env["subscription.request"].search([("_api_external_id", "=",
                                                    _id)])
     if not sr:
         raise wrapJsonException(
             NotFound(_("No subscription request for id %s") % _id))
     sr.write(params)
     return self._to_dict(sr)