mwolff44 / pk-sbc

P-KISS-SBC - simple and stupid SIP/RTP SBC - AGPL v3 - Based on kamailio / RTP Engine
https://pk-sbc.io
GNU Affero General Public License v3.0
99 stars 50 forks source link

DIDs without Provider or customer rate plan fail #151

Closed freddy36 closed 5 years ago

freddy36 commented 6 years ago

Currently the django DID model doesn't require Provider rate plan or Customer rate plan to be set.

But if they aren't set freeswitch routing fails because it generates the following invalid SQL queries with empty ID values:

SELECT
rc.lcrgroup_id AS lcrgroup_id,                                                                                                                                                                                               
rc.callerid_filter AS callerid_filter,                                                                                                                                                                                       
rc.rctype AS rctype,                                                                                                                                                                                                         
rc.id AS ratecard_id,                                                                                                                                                                                                        
r.destination AS destination,                                                                                                                                                                                                
r.prefix AS prefix,                                                                                                                                                                                                          
r.rate AS rate,                                                                                                                                                                                                              
r.block_min_duration AS block_min_duration,                                                                                                                                                                                  
r.init_block AS init_block,                                                                                                                                                                                                  
r.minimal_time AS minimal_time,                                                                                                                                                                                              
0 AS discount                                                                                                                                                                                                                
FROM ratecard rc                                                                                                                                                                                                             
INNER JOIN customer_rates r                                                                                                                                                                                                  
    ON rc.id = r.ratecard_id AND rc.rctype = 'DIDIN'                 WHERE rc.enabled = TRUE                                                                                                                                   
    AND rc.id = ''                                                                                                                                                                                                             
    AND r.enabled = true                                                                                                                                                                                                       
    AND now() > rc.date_start                                                                                                                                                                                                  
    AND now() < rc.date_end                                                                                                                                                                                                    
    AND '4961518614771' LIKE concat(r.prefix,'%')                                                                                                                                                                              
ORDER BY LENGTH(r.prefix) desc LIMIT 1;    

Note the AND rc.id = '' The same happens for provider rates.

I worked around this by creating corresponding dummy ratecards but I personally would prefer to fix the freeswitch script to support inbound calls without ratecard.

mwolff44 commented 6 years ago

It is normal as i can not force it for the setup, but it is needed for routing. I think to make it evolve and to use genering ratecard for did attached to customer. What do you think about that ?

freddy36 commented 6 years ago

there are probably good use case for both design choices (attaching the ratecard to the customer vs attaching it to the DID route). Attaching it to the DID route (the current design) is probably the more flexible solution.

If it's not possible to change the freeswitch script to handle calls without ratecards I suggest to add a form check to make sure prov_ratecard and cust_ratecard is set if customer is configured.

mwolff44 commented 6 years ago

i thought to add a choice to use free did (customer and provider). With a boolean, so no needs of ratecards in this case ! My customers use the same prices for all did (depending on prefix) so associating a ratecard to a customer and a provider is simple for them. I prefer always simple things. What do you think about that ?

freddy36 commented 6 years ago

99% of our customers don't pay anything for DIDs so a simple free checkbox (or default free if ratecards are not configured) would make things simpler for us. Moving the ratecard associations to the provider/customer sounds ok to me too.

The simplest solution for me would be not to use ratecards at all for DIDs, instead configure the buy/sell charges directly at the DID level. That's probably the most user friendly way (But would break some (future) use cases). Personally we would prefer to keep it like it is or just move the ratecard associations to provider/customer. (or hide them from the GUI)

mwolff44 commented 6 years ago

OK, i will change this

mwolff44 commented 6 years ago

i will publish it in the same time of outbound calls modifications. I am moving this part from FS script to kamailio.

mwolff44 commented 5 years ago

Done in the next release